home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / misc / GadMget1_9.lha / GadMGet1.9 / GadMget1.9.source.lha / gadmget.c < prev    next >
C/C++ Source or Header  |  1995-02-02  |  90KB  |  3,764 lines

  1. /* GadMGet.c  by Jeremy Friesner -- jfriesne@ucsd.edu  
  2.    Version 1.9, released 03 February 1995 */
  3.  
  4. #ifndef MGET_C
  5. #define MGET_C
  6.  
  7. #define INTUI_V36_NAMES_ONLY
  8. #define MAXFILELINELENGTH 300 
  9. #define CHAR_SPACE ' '
  10. #define INVALID 666
  11.  
  12. #define FIND_REQUESTTYPE               0
  13. #define LINELENGTH_REQUESTTYPE          1
  14. #define OUTPUTFILE_REQUESTTYPE          2
  15. #define SELECT_REQUESTTYPE           3
  16. #define DESELECT_REQUESTTYPE         4
  17.  
  18. #define SEARCH_FORWARD 1
  19. #define SEARCH_BACKWARD 2
  20. #define SEARCHTYPE_BOTTOM 1
  21. #define SEARCHTYPE_TOP 2
  22. #define SEARCHTYPE_NEXT 3
  23. #define SEARCHTYPE_PREVIOUS 4
  24. #define SEARCHTYPE_FORWARD 5
  25. #define SEARCHTYPE_BACKWARD 6
  26.  
  27. #define SORTBYDIR  1
  28. #define DIRNAMESIZE 10
  29.  
  30. #define SORTBYNAME 2
  31. #define NAMESIZE 20
  32.  
  33. #define SORTBYDESC 3
  34. #define DESCSIZE 42
  35.  
  36. #define SORTBYSIZE 4
  37. #define SIZESIZE 5
  38.  
  39. #define SORTBYAGE  5
  40. #define AGESIZE  5
  41.  
  42. #define TREESORT   1
  43. #define BUBBLESORT 2
  44.  
  45. #include "GadMget.h"
  46.  
  47. extern UWORD lastcode;
  48. extern ULONG appwinsig;
  49. extern struct NewGadget mgetNGad[];
  50. extern struct NewMenu mgetNewMenu[];
  51. extern struct Window *findwindow;
  52. extern struct AppMessage *amsg;
  53. extern struct MsgPort *awport;
  54. extern struct AppWindow *appwin;
  55. extern struct TextAttr listfont;
  56.  
  57. extern LONG lTreeTicker;
  58. extern LONG lTreeSubTicker;
  59. extern char *sTreeWriteHere;
  60. extern char *szTickerString;
  61.  
  62. FILE *fpOut = stdout;
  63. int IntuitionBase; 
  64. ULONG winopenerror, lockscrnerror;
  65. ULONG handlereturn;
  66. BOOL done=FALSE,BStartedFromWB=FALSE;
  67. char windowtitle[95] = "Loading...";
  68. char sListFontName[36] = "";
  69. int nListFontSize = 0;  /* Default to a bad value */
  70. char version[] = "$VER: GadMget V1.9";
  71. char template[] = "Template:  GadMGet FILE/A,OUTPUT/K,LINELENGTH/K,TOP/K,LEFT/K,\
  72. WIDTH/K,HEIGHT/K,PUBSCREEN/K,WBSCREEN/S,DEFPUBSCREEN/S,NOFILES/S,GETREADMES/S,\
  73. NOPARSE/S,CASESENSITIVE/S,SORTCASESENSITIVE/S,SEARCHCASESENSITIVE/S,NOCOMMAND/S,\
  74. NOSPLIT/S,NOAPPWINDOW/S,COMMAND/K,NOSIMPLEPATHS/S,NOCD/S,HEADER/K,FOOTER/K,\
  75. FONT/K,FONTSIZE/K,KEEPBLANKLINES/S,KEEPGETSORT/S,KEEPFILESORT/S,FILESORT/K,\
  76. GETSORT/K,AMINETPATH/K,EOL/K\n";
  77. char pnamestring[20],searchstring[MAXFILELINELENGTH];
  78. char szPubScreenName[40],*pubscreenname = NULL,defDir[200],defFile[40];
  79. char szCommandString[40] = "mget ";
  80. char inputfile[300]="ram:RECENT";
  81. char sEndOfLineString[10] = "\r\n";
  82. char sAminetPathString[50] = "../../";
  83. char sOutFileName[300]="";
  84. char szHeaderFile[300];
  85. char szFooterFile[300];
  86. char sMultiSelect[150]="";
  87. int nTopListTop, nTopListHeight, nBottomListHeight;
  88. int nSortType[2] = {SORTBYDIR, SORTBYDIR};
  89. int nKeepSorted[2] = {FALSE, FALSE};
  90. int Not[2] = {TRUE, FALSE};        /* NOT lookup array */
  91. int nForTreeSortUseOnly;    /* only global because nested functions ain't happenin!  Don't use elsewhere! */
  92. struct List *lForTreeSortUseOnly;
  93.  
  94. /* Input column info */
  95. static int nNameCol = 0;
  96. static int nKCol    = 35;
  97. static int nDirCol  = 21;
  98. static int nAgeCol  = 35;  /* Not that this should be the RIGHT side of the age string! */
  99. static int nPlusCol = 36;
  100. static int nDescCol = 37;
  101.  
  102. /* default flags */
  103. int screentype              = USE_CUSTOMSCREEN,    
  104.      getreadmes             = FALSE, 
  105.      filesflag           = TRUE,                 /* get .lha files */
  106.      filelist_length      = 0,                      /* no files loaded */
  107.      getlist_length      = 0,                     /* no files selected either */
  108.      search_index         = 0,                     /* buffer at first item */
  109.      mgetfind_findtype   = SEARCHTYPE_FORWARD,   /* global var used between mgetfind* */
  110.      simplepaths          = TRUE,                 /* don't use ncftp style mgets */
  111.      searchcasesensitive = FALSE,
  112.      sortcasesensitive   = FALSE,                    
  113.      maxoutputlinelength = 254,                  /* shell's limit */
  114.      requesttype          = FIND_REQUESTTYPE,     /* subwindow is for string searches */
  115.      nSortAlgorithm      = TREESORT,             /* default sort type */
  116.      appwindow              = TRUE,                 /* = YES */
  117.      added_bytes          = 0,                     /* used for debugging-- tracks */
  118.                                                    /* the # of bytes allocated */
  119.      files_selected      = 0,                        /* no files selected */
  120.      screenisopen          = FALSE,                 /* = NO */
  121.      windowisopen          = FALSE,                  /* = NO */
  122.      noparse              = FALSE,                  /* = yes, parse */
  123.      nocommand             = FALSE,                 /* = yes, generate command */
  124.      nosplit              = FALSE,                 /* = yes, split */
  125.      nocd                 = FALSE,                 /* = generate CD commands */
  126.      mgetNGad_height      = 248,                     /* default first listview height */
  127.      keepblanklines         = FALSE;                /* = don't show blank lines */
  128.  
  129. ULONG kbytes_selected = 0;                                
  130.      
  131. UWORD windowwidth       = MAXINT,                    /* window will be sized to fill */
  132.         windowheight  = MAXINT,                    /* screen unless these are */
  133.         windowtop       = 0,                         /* overridden by parameters */
  134.         windowleft       = 0;
  135.         
  136.  
  137. void *findvi = NULL;
  138.  
  139. struct Library *Intuitionbase            = NULL;
  140. struct GfxBase *GraphicsBase            = NULL;
  141. struct Library *GadToolsBase            = NULL;
  142. struct Library *UtilityBase                = NULL;
  143. struct Library *AslBase                    = NULL;
  144. struct Library *IconBase                = NULL;
  145. struct Library *WorkbenchBase            = NULL;
  146. struct WBArg *argptr = NULL;
  147.  
  148. struct IntuiMessage *message                 = NULL;
  149. struct List *filelist                         = NULL, 
  150.                 *getlist                         = NULL;
  151. struct Node *search_current                 = NULL;
  152. struct Gadget *findgadlist                 = NULL;
  153. struct TextFont *listfontdata = NULL;
  154.  
  155. __chip UWORD waitPointer[] =
  156.     {
  157.     0x0000, 0x0000,
  158.     0x0400, 0x07c0,
  159.     0x0000, 0x07c0,
  160.     0x0100, 0x0380,
  161.     0x0000, 0x07e0,
  162.     0x07c0, 0x1ff8,
  163.     0x1ff0, 0x3fec,
  164.     0x3ff8, 0x7fde,
  165.     0x3ff8, 0x7fbe,
  166.     0x7ffc, 0xff7f,
  167.     0x7efc, 0xffff,
  168.     0x7ffc, 0xffff,
  169.     0x3ff8, 0x7ffe,
  170.     0x3ff8, 0x7ffe,
  171.     0x1ff0, 0x3ffc,
  172.     0x07c0, 0x1ff8,
  173.     0x0000, 0x07e0,
  174.     0x0000, 0x0000};
  175.     
  176.  
  177. void debug(int a)
  178. {
  179.     fprintf(fpOut,"debug  %i\n",a);
  180.     Delay(80);
  181. }
  182.  
  183.  
  184.  
  185.  
  186. void EOLParse(char *sString)
  187. {
  188. char sTempString[50], sTemp2[2] = " "; 
  189. char * sCurrent = sString;
  190. int i=0, nStringLength;
  191.  
  192. if (sString == NULL) return;
  193. nStringLength = strlen(sString); 
  194. memset(sTempString,'\0',sizeof(sTempString));
  195.  
  196. while ((i<(sizeof(sTempString)-1))&&(*sCurrent != '\0'))
  197. {
  198.     if (*sCurrent == '\\')
  199.     {
  200.         sCurrent++; i++;
  201.         switch(*sCurrent)
  202.         {
  203.             case 'r':
  204.                 strncat(sTempString,"\r",sizeof(sTempString));
  205.             break;
  206.             
  207.             case 'n':
  208.                 strncat(sTempString,"\n",sizeof(sTempString));
  209.             break;
  210.         
  211.             case '\0':
  212.                 i = nStringLength + 1;    /* get out of the loop! */
  213.             break;
  214.             
  215.             case '\\':
  216.                 strncat(sTempString,"\\",sizeof(sTempString));
  217.             break;                
  218.             
  219.             default:
  220.                 sTemp2[0] = *sCurrent;
  221.                 strncat(sTempString,"\\",sizeof(sTempString));                
  222.                 strncat(sTempString,sTemp2,sizeof(sTempString));
  223.                 i++;
  224.             break;
  225.         }
  226.     }
  227.     else
  228.     {
  229.         sTemp2[0] = *sCurrent;
  230.         strncat(sTempString, sTemp2, sizeof(sTempString));
  231.         i++;
  232.     }
  233.     sCurrent++;
  234. }
  235. strncpy(sString,sTempString,nStringLength);
  236. return;
  237. }
  238.  
  239.  
  240.  
  241.  
  242.  
  243. /* If *index isn't NULL, that location will be set to the index
  244.    value of the tail of the list */
  245. struct Node * TailOf(struct List *thislist, int *index)
  246. {
  247.     struct Node *CurrentNode = thislist->lh_Head;
  248.     int nTempIndex = 0;
  249.     
  250.     /* traverse to tail of list */
  251.     while ((CurrentNode != NULL)&&(CurrentNode->ln_Succ != NULL))
  252.     {
  253.         nTempIndex++;
  254.         CurrentNode = CurrentNode->ln_Succ;
  255.     }
  256.  
  257.     if (index != NULL) *index = nTempIndex;
  258.  
  259.     return(CurrentNode);
  260. }
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267. /* Return index in list of the current 1st visible node */
  268. LONG ListViewTop (struct Gadget *gad, struct Window *win)
  269. {
  270.    LONG top;
  271.  
  272.     /* use Official attributes function if running under 3.0+, otherwise
  273.        hack into the Gadget struct to find out */
  274.    if (GadToolsBase->lib_Version >= 39)
  275.       GT_GetGadgetAttrs (gad, win, NULL, GTLV_Top, &top, TAG_END);
  276.    else
  277.       top = (LONG)(*(short *)(((char *)gad)+sizeof(struct Gadget)+4));
  278.  
  279.    return (top);
  280. }
  281.  
  282.  
  283.  
  284. /* return pointer to first visible node in thisGad, thislist */
  285. struct Node * ListViewTopNode(struct Gadget *thisGad, struct List *thislist)
  286. {
  287.     int nTemp = 0;
  288.     int nTop = ListViewTop(thisGad,mgetWnd);
  289.     struct Node *CurrentNode = NULL;
  290.  
  291.     CurrentNode = thislist->lh_Head;
  292.     while (nTemp < nTop) {CurrentNode = CurrentNode->ln_Succ; nTemp++;}
  293.     return(CurrentNode);
  294. }
  295.  
  296.  
  297.  
  298. int isAminetParsable(char *dataline)
  299. {
  300.     BOOL BValidLine;
  301.     
  302.     /* check to make sure string is a valid file line */
  303.     if ((dataline == NULL)||(dataline[0] == '\0')||(dataline[Not[keepblanklines]] == '\0')) return(FALSE);    
  304.         
  305.     if (!noparse)
  306.     {
  307.         if (((dataline[nNameCol] < '0')||(dataline[nNameCol] > 'z')) ||
  308.             ((dataline[nKCol] != 'K')&&(dataline[nKCol] != 'M')&&(dataline[nKCol] != '?')) || 
  309.             (dataline[nDirCol] < '0') || (dataline[nDirCol] > 'z') ||
  310.             (dataline[nDescCol] < 'A') || (dataline[nDescCol] > 'z') ||
  311.             ((dataline[nPlusCol] != '+')&&(dataline[nPlusCol] != '*')&&(dataline[nPlusCol] != ' ')) ||
  312.             ((filesflag == 0)&&(dataline[nPlusCol] != '+')))
  313.         {
  314.             /* Problem line--rescan! */
  315.             BValidLine = ReScanAminetLine(dataline);
  316.             if (filesflag == 0) return(BValidLine && (dataline[nPlusCol] == '+'));
  317.             else return(BValidLine);
  318.         }
  319.     }    
  320.     return(TRUE);
  321. }
  322.  
  323.  
  324. /* This function looks at an Aminet line and if successful, will update
  325.    the global n#?Col variables to reflect the columns found in this line
  326.    Returns 0 on failure (and won't update the global vars), or 1 on 
  327.    success (vars were all updated) */
  328. int ReScanAminetLine(char *dataline)
  329. {
  330.     BOOL BDone = FALSE;
  331.     int nCount = 0;
  332.     int nTempNameCol = -1;
  333.     int nTempKCol    = -1;
  334.     int nTempDirCol  = -1;
  335.     int nTempPlusCol = -1;
  336.     int nTempDescCol = -1;
  337.     int nState = 0;                /* State 0 = haven't found filename yet */
  338.                                 /* State 1 = reading thru filename */
  339.                                 /* State 2 = haven't found directory yet */
  340.                                 /* State 3 = haven't found K/M thingy yet */
  341.                                 /* State 4 = haven't found weeks yet */
  342.                                 /* State 5 = Looking for plus symbol */
  343.                                 /* State 6 = Backtracking for age field */
  344.     char *pcThisChar = dataline;
  345.     
  346.     if (pcThisChar == NULL) return(0);
  347.     
  348.     while((*pcThisChar != '\0')&&(BDone == FALSE))
  349.     {
  350.         switch (nState)
  351.         {
  352.             case 0:        /* Looking for start of file name */
  353.                 if ((*pcThisChar >= '0')&&(*pcThisChar <= 'z'))
  354.                 {
  355.                     nTempNameCol = nCount;
  356.                     nState = 1;
  357.                 }
  358.                 pcThisChar++; 
  359.                 nCount++;
  360.                 break;
  361.             
  362.             case 1:        /* Reading thru filename */
  363.                 if (*pcThisChar == ' ')
  364.                 {
  365.                     nState = 2;
  366.                 }
  367.                 else
  368.                 {
  369.                     pcThisChar++; 
  370.                     nCount++;
  371.                 }
  372.                 break;
  373.             
  374.             case 2:    /* Moving over spaces after filename */
  375.                 if (*pcThisChar != ' ')
  376.                 {
  377.                     nTempDirCol = nCount;
  378.                     nState = 3;
  379.                 }
  380.                 pcThisChar++;
  381.                 nCount++;
  382.                 break;
  383.             
  384.             case 3:    /* Moving thru directory */
  385.                 if (*pcThisChar == ' ')
  386.                 {
  387.                     nState = 4;
  388.                 }
  389.                 pcThisChar++;
  390.                 nCount++;
  391.                 break;
  392.             
  393.             case 4: /* Looking for KCol */
  394.                 if ((*pcThisChar == 'K')||(*pcThisChar == 'M')||(*pcThisChar == '?'))
  395.                 {
  396.                     nTempKCol = nCount;
  397.                     nState = 5;
  398.                 }        
  399.                 pcThisChar++;
  400.                 nCount++;
  401.                 break;
  402.             
  403.             case 5: /* Looking for plus symbol */
  404.                 if (*pcThisChar == '+')
  405.                 {
  406.                     nTempPlusCol = nCount;
  407.                     nTempDescCol = nCount + 1;
  408.                     nState = 6;
  409.                     pcThisChar--;    /* move back to the left of + */
  410.                     nCount--;
  411.                 }
  412.                 else if ((*pcThisChar > '9')&&(*pcThisChar < '0')&&(*pcThisChar != ' '))
  413.                 {
  414.                     nTempPlusCol = nCount - 1;
  415.                     if (nTempPlusCol < 0) nTempPlusCol = 0;
  416.                     nTempDescCol = nCount;
  417.                     nState = 6;
  418.                     pcThisChar -= 2;    /* move back to the left of the */
  419.                     nCount     -= 2;    /* first comment char AND the space */
  420.                 }
  421.                 else
  422.                 {
  423.                     pcThisChar++;
  424.                     nCount++;
  425.                 }
  426.                 break;
  427.         
  428.             case 6: /* Backtracking, looking for rightmost digit in age column */
  429.                 if (((*pcThisChar >= '0')||(*pcThisChar <= '9'))||(nCount == 0))
  430.                 {
  431.                     nAgeCol = nCount;
  432.                     BDone = TRUE;
  433.                 }
  434.                 else
  435.                 {
  436.                     pcThisChar--;
  437.                     nCount--;
  438.                 }
  439.                 break;
  440.         }
  441.     }        
  442.     
  443.     /* Now we see if we've got something valid */
  444.     if (nState < 5) return(0);
  445.     
  446.     /* This in case there was no plus on this line! */
  447.     if (nTempPlusCol == -1) nTempPlusCol = nTempKCol + 1;
  448.     if (nTempDescCol == -1) nTempDescCol = (nTempPlusCol + (dataline[nTempPlusCol] != '\0'));
  449.     
  450.     /* Assign global vars */
  451.     nNameCol = nTempNameCol;
  452.     nDirCol  = nTempDirCol;
  453.     nKCol    = nTempKCol;
  454.     nPlusCol = nTempPlusCol;
  455.     nAgeCol  = nTempPlusCol - 1;
  456.     nDescCol = nTempDescCol;
  457.     if (nAgeCol < 0) nAgeCol = 0;
  458.     return(1);
  459. }
  460.     
  461.     
  462.     
  463.             
  464. int listviewgadgetClicked (VOID)
  465. {
  466. int i;
  467. struct Node *current = filelist->lh_Head;
  468. char *dataline = NULL;
  469.  
  470.  
  471.  for (i=0; i<lastcode; i++) current = current->ln_Succ;
  472.  
  473.  if (current != NULL)
  474.  {
  475.     /* Take it out of filelist */
  476.     GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  477.     GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  478.  
  479.     TransferToSelected(current);
  480.  
  481.     GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  482.     GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
  483.  }
  484.  return(1);    
  485. }
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493. int list2Clicked (VOID)
  494. {
  495.  /* This function will move a clicked item from the lower list to the upper one */
  496.  int i;
  497.  struct Node *current = getlist->lh_Head;
  498.  
  499.  for (i=0; i<lastcode; i++) current = current->ln_Succ;
  500.     
  501.  if (current != NULL)
  502.  {
  503.     GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  504.     GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  505.  
  506.     TransferToFiles(current);
  507.  
  508.     GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
  509.     GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  510.  }
  511. }
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518. void TransferToSelected(struct Node *current)
  519. {
  520.  
  521.     if (isAminetParsable(current->ln_Name) == FALSE) return;  /* don't transfer what you cant understand */
  522.  
  523.     UpdateByteCount(current->ln_Name,1);
  524.     
  525.     /* Watch out for the nasty case where our search buffer just got removed */
  526.     if (search_current == current) 
  527.     {
  528.         if (search_current->ln_Pred != NULL)
  529.         {
  530.             search_current = search_current->ln_Pred;
  531.             search_index--;
  532.         }
  533.         else
  534.         {
  535.             search_current = search_current->ln_Succ;
  536.             search_index++;
  537.         }
  538.         
  539.         /* Check to see if we've walked off the front or back of the list */
  540.         /* If we have, default to the head of the list */
  541.         if (search_current == NULL) 
  542.         {
  543.             
  544.                 search_current = filelist->lh_Head;
  545.                 search_index = 0;
  546.         }
  547.     }
  548.  
  549.     Remove(current);
  550.     /* And insert it in getlist */
  551.     if ((nKeepSorted[1] == 1)&&(!noparse))
  552.     {
  553.         SmartAdd(getlist,current,nSortType[1]);
  554.     }
  555.     else
  556.     {
  557.         AddTail(getlist,current);
  558.     }
  559.     
  560.     
  561.     files_selected++;
  562.     filelist_length--;
  563.     getlist_length++;
  564.     
  565.     ChangeWindowTitle();
  566. }
  567.  
  568.  
  569.  
  570.  
  571. void TransferToFiles(struct Node *current)
  572. {
  573.     UpdateByteCount(current->ln_Name,-1);
  574.  
  575.     /* Take it out of getlist */
  576.     Remove(current);
  577.     current->ln_Succ = NULL;        /* Clear now invalid field */
  578.  
  579.     /* And insert it in filelist */
  580.      if ((nKeepSorted[0] == 1)&&(!noparse))
  581.      {    
  582.          SmartAdd(filelist,current,nSortType[0]);
  583.      }
  584.     else
  585.     {
  586.         AddTail(filelist,current);
  587.     }
  588.     
  589.     /* and that's it! */
  590.     files_selected--;
  591.     filelist_length++;
  592.     getlist_length--;
  593.  
  594.     ChangeWindowTitle();
  595. }
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604. /* Returns file size, in weeks, of the given Aminet line--only
  605.    works if said file size is available, of course */
  606. int AminetFileAge(char *sString)
  607. {
  608.     int nTemp;
  609.     int nSum = 0;
  610.     
  611.     if (isAminetParsable(sString) == FALSE) return(0);
  612.     nTemp = nAgeCol;
  613.     
  614.     /* If no date available on this line, return error. */
  615.     if ((sString[nTemp] < '0')||(sString[nTemp] > '9')) return(-999);
  616.     
  617.     while ((sString[nTemp] >= '0')&&(sString[nTemp] <= '9')&&(nTemp >= 0))
  618.     {
  619.         nSum *= 10;
  620.         nSum += sString[nTemp] - '0';
  621.         nTemp--;
  622.     }
  623.     
  624.     return(nSum);
  625. }
  626.  
  627.  
  628.  
  629. int AminetFileSize(char *sString)
  630. {
  631. /* Returns file size, in kilobytes, of the given Aminet line */
  632. int multiplier;
  633. int filesize = 0, wholenum;
  634. int outputlength = -1;
  635. int tenthofmultiplier = 0;
  636.  
  637.     if (isAminetParsable(sString) == FALSE) return(0);
  638.     
  639.     switch (sString[nKCol])
  640.     {
  641.         case 'M':
  642.             multiplier = 1024;   /* 1024 k in a M */
  643.             tenthofmultiplier = 102;
  644.             break;
  645.             
  646.         case 'K': 
  647.             multiplier = 1;     /* 1 k in a k */
  648.             break;
  649.         
  650.         case '?':
  651.             multiplier = 0;
  652.             break;
  653.             
  654.         default:
  655.             return(FALSE);
  656.     }
  657.     
  658.     if (sString[nKCol-2] == '.')        /* for when it's like:  3.5M */
  659.     {
  660.         /* figure out kilobytes */
  661.         wholenum = (int) (sString[nKCol-3] - '0');
  662.         
  663.         if ((wholenum >= 0)&&(wholenum <= 9)) filesize = filesize + (multiplier * wholenum);
  664.         
  665.         wholenum = (int) (sString[nKCol-1] - '0');
  666.         if ((wholenum >= 0)&&(wholenum <= 9)) filesize = filesize + (tenthofmultiplier * wholenum);
  667.     }
  668.     else
  669.     {
  670.         wholenum = (int) (sString[nKCol-3] - '0');
  671.         if ((wholenum >= 0)&&(wholenum <= 9)) filesize = filesize + (100 * multiplier * wholenum);
  672.  
  673.         wholenum = (int) (sString[nKCol-2] - '0');
  674.         if ((wholenum >= 0)&&(wholenum <= 9)) filesize = filesize + ( 10 * multiplier * wholenum);
  675.  
  676.         wholenum = (int) (sString[nKCol-1] - '0');
  677.         if ((wholenum >= 0)&&(wholenum <= 9)) filesize = filesize + (      multiplier * wholenum);
  678.     }
  679.     
  680.     return(filesize);
  681. }
  682.  
  683.  
  684.  
  685. void SmartAdd(struct List *thislist, struct Node *addme, int nThisSortType)
  686. {
  687. /* a simple add into the correct order of the list */
  688. struct Node *current, *past;
  689. char sBuffer1[43], sBuffer2[43];
  690.  
  691. current = thislist->lh_Head;
  692. past = NULL;
  693.  
  694. if ((addme == NULL)||(addme->ln_Name == NULL)) 
  695. {
  696.     printf("Tell Jeremy--bug #5!\n");
  697.     return();
  698. }
  699.  
  700. while (current != NULL)            
  701.         {
  702.             /* Only sort if this is an Aminet file line, or not an Aminet Sort */    
  703.             if ((current->ln_Name != NULL)&&(isAminetParsable(current->ln_Name)&&isAminetParsable(addme->ln_Name)))
  704.             {
  705.                 switch(nThisSortType)
  706.                 {
  707.                     case SORTBYDIR:
  708.                         strncpy(sBuffer1,addme->ln_Name+nDirCol,DIRNAMESIZE);
  709.                         strncpy(sBuffer2,current->ln_Name+nDirCol,DIRNAMESIZE);
  710.                         if ((strchr(sBuffer1,'/') != NULL)&&
  711.                              (strchr(sBuffer2,'/') != NULL)&&
  712.                               (strncmp(sBuffer1,sBuffer2,DIRNAMESIZE) < 0))
  713.                         {
  714.                             Insert(thislist, addme, past);    /* and put it back in after current */
  715.                             return();
  716.                         }
  717.                     break;
  718.                 
  719.                     case SORTBYDESC:
  720.                         if (strncmp(addme->ln_Name+nDescCol,current->ln_Name+nDescCol,DESCSIZE) < 0)
  721.                         {
  722.                             Insert(thislist, addme, past);    /* and put it back in after current */
  723.                             return();
  724.                         }
  725.                     break;
  726.                     
  727.                     case SORTBYNAME:
  728.                         memset(sBuffer1,NUL,NAMESIZE);  /* sort sometimes goes into infinite loops if you don't have this??? */
  729.                         memset(sBuffer2,NUL,NAMESIZE);  /* It shouldn't, though, because strncpy terminates everything right? */
  730.                         strncpy(sBuffer1,addme->ln_Name+nNameCol,NAMESIZE);
  731.                         strncpy(sBuffer2,current->ln_Name+nNameCol,NAMESIZE);    
  732.                         if (strncmp(sBuffer1,sBuffer2,NAMESIZE) < 0)
  733.                         {
  734.                             Insert(thislist, addme, past);    /* and put it back in after current */        
  735.                             return();
  736.                         }
  737.                     break;
  738.                     
  739.                     case SORTBYSIZE:
  740.                         if (AminetFileSize(addme->ln_Name) < AminetFileSize(current->ln_Name))
  741.                         {
  742.                             Insert(thislist, addme, past);    /* and put it back in after current */
  743.                             return();
  744.                         }
  745.                         
  746.                     case SORTBYAGE:
  747.                         if (AminetFileAge(addme->ln_Name) < AminetFileAge(current->ln_Name))
  748.                         {
  749.                             Insert(thislist, addme, past);    /* and put it back in after current */
  750.                             return();
  751.                         }
  752.  
  753.                     break;
  754.                 }
  755.             }    
  756.             past = current;                /* step to next in list */
  757.             current = current->ln_Succ;
  758.         }
  759.         
  760.     AddTail(thislist,addme);        /* If we've got to the end without returning, add it to the end */
  761.     return();
  762. }
  763.  
  764.  
  765.  
  766.  
  767.  
  768. int CompareByDir(struct Node *past, struct Node *current)
  769. {
  770.     static char sBuffer1[43], sBuffer2[43];  /* static to avoid re- and de-allocing */
  771.     
  772.     if (isAminetParsable(current->ln_Name) == FALSE) return(-999);     /* error! */
  773.          
  774.     if (sortcasesensitive == TRUE) 
  775.         return(strncmp(past->ln_Name+nDirCol,current->ln_Name+nDirCol,DIRNAMESIZE));  /* For Lists, > 0 = switch */
  776.  
  777.     /* case insensitive */    
  778.     strncpy(sBuffer1,past->ln_Name+nDirCol,DIRNAMESIZE);
  779.     strncpy(sBuffer2,current->ln_Name+nDirCol,DIRNAMESIZE);
  780.     UpperCase(sBuffer1);        /* not case sensitive */
  781.     UpperCase(sBuffer2);
  782.     
  783.     return(strncmp(sBuffer1,sBuffer2,DIRNAMESIZE));  /* For Lists, > 0 = switch */
  784. }
  785.  
  786.  
  787.  
  788.     
  789. int CompareByDesc(struct Node *past, struct Node *current)
  790. {
  791.     static char sBuffer1[43], sBuffer2[43];  /* static to avoid re- and de-allocing */
  792.  
  793.     /* Make sure the comment is ok! */
  794.     if (isAminetParsable(current->ln_Name) == FALSE) return(-999);     /* error! */
  795.     
  796.     if (sortcasesensitive == TRUE) return(strncmp(past->ln_Name+nDescCol,current->ln_Name+nDescCol,DESCSIZE));
  797.  
  798.     /* For Lists, > 0 = switch */
  799.     strncpy(sBuffer1,past->ln_Name+nDescCol,DESCSIZE);        /* copies to modify */
  800.     strncpy(sBuffer2,current->ln_Name+nDescCol,DESCSIZE);    
  801.     UpperCase(sBuffer1);        /* not case sensitive */
  802.     UpperCase(sBuffer2);
  803.     
  804.    return(strncmp(sBuffer1, sBuffer2,DESCSIZE));
  805.     
  806.  
  807.  
  808.     
  809.  
  810.  
  811. int CompareByName(struct Node *past, struct Node *current)
  812. {
  813.     static char sBuffer1[43], sBuffer2[43];  /* static to avoid re- and de-allocing */
  814.  
  815.     /* Make sure the comment is ok! */
  816.     if (isAminetParsable(current->ln_Name) == FALSE) return(-999);     /* error! */
  817.  
  818.     if (sortcasesensitive == TRUE) return(strncmp(past->ln_Name+nNameCol,current->ln_Name+nNameCol,NAMESIZE));
  819.     
  820.     /* case insensitive test below */    
  821.     strncpy(sBuffer1,past->ln_Name+nNameCol,NAMESIZE);
  822.     strncpy(sBuffer2,current->ln_Name+nNameCol,NAMESIZE);    
  823.     UpperCase(sBuffer1);
  824.     UpperCase(sBuffer2);
  825.     
  826.     return(strncmp(sBuffer1,sBuffer2,NAMESIZE));
  827. }
  828.  
  829.  
  830.  
  831.  
  832.  
  833. int CompareBySize(struct Node *past, struct Node *current) 
  834. {
  835.     return(AminetFileSize(past->ln_Name) - AminetFileSize(current->ln_Name));
  836. }
  837.  
  838.  
  839. int CompareByAge(struct Node *past, struct Node *current) 
  840. {
  841.     return(AminetFileAge(past->ln_Name) - AminetFileAge(current->ln_Name));
  842. }
  843.  
  844.  
  845. void SortList(struct List *thislist, int nThisSortType)
  846. {
  847.     static char sSortTypeString[40];
  848.     char *sSortWinString;
  849.     
  850.     strcpy(sSortTypeString, "Sorting by \0");
  851.     
  852.     if (windowisopen) SetWindowTitles(mgetWnd, "Sorting--please be patient", (char *) ~0); 
  853.  
  854.     /* Generate Window title prompt */
  855.     switch(nThisSortType)
  856.     {
  857.         case SORTBYDIR:
  858.             strcat(sSortTypeString,"Directory: ");
  859.         break;
  860.         
  861.         case SORTBYSIZE:
  862.             strcat(sSortTypeString,"Size: ");
  863.         break;
  864.         
  865.         case SORTBYDESC:
  866.             strcat(sSortTypeString,"Description: ");
  867.         break;
  868.  
  869.         case SORTBYNAME:
  870.             strcat(sSortTypeString,"FileName: ");
  871.         break;
  872.         
  873.         default:
  874.             strcat(sSortTypeString,"Unknown: ");
  875.         break;
  876.     }
  877.  
  878.     sSortWinString = strrchr(sSortTypeString,' ') + 1;        /* Where to write next */
  879.     sTreeWriteHere = sSortWinString;
  880.     szTickerString = sSortTypeString;
  881.             
  882.     if (thislist == NULL) return;
  883.     
  884.     /* Remove list from ListView if necessary  */
  885.      if (windowisopen)
  886.      {
  887.           if (thislist == filelist) GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  888.          if (thislist ==  getlist) GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  889.         SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  890.     }
  891.  
  892.     switch (nSortAlgorithm)
  893.     {
  894.          case BUBBLESORT: BubbleSortList(thislist, nThisSortType, sSortWinString, sSortTypeString); break;
  895.          case TREESORT:   TreeSortList  (thislist, nThisSortType, sSortWinString, sSortTypeString); break;
  896.      }
  897.      
  898.      if (windowisopen)
  899.     {
  900.         /* Replace list into ListView */
  901.         if (thislist == filelist) GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  902.         if (thislist ==  getlist) GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels,  getlist, TAG_END);
  903.         ClearPointer(mgetWnd);
  904.     }
  905.     ChangeWindowTitle();
  906.  
  907. }
  908.  
  909.  
  910.  
  911.  
  912.  
  913. int TreeSortUserCompare(struct Node *thisnode, struct Node *thatnode)
  914. {
  915.     int nResult;
  916.         
  917.     switch(nForTreeSortUseOnly)  /* using a global variable here stinks :( */
  918.     {
  919.         case SORTBYDIR:  nResult = CompareByDir (thisnode, thatnode); break;
  920.         case SORTBYNAME: nResult = CompareByName(thisnode, thatnode); break;
  921.         case SORTBYSIZE: nResult = CompareBySize(thisnode, thatnode); break;
  922.         case SORTBYDESC: nResult = CompareByDesc(thisnode, thatnode); break;
  923.         case SORTBYAGE:  nResult = CompareByAge (thisnode, thatnode); break;
  924.     }
  925.     if (nResult == 0) return(1);  /* default value can't be zero! */
  926.     return(nResult);
  927. }
  928.  
  929.  
  930.  
  931.  
  932. void TreeSortList(struct List *thislist, int nThisSortType, char *sSortWinString, char *sSortTypeString)    
  933. {
  934.     struct Node *CurrentNode = thislist->lh_Head;
  935.     tree *mytree = NULL;                                    
  936.     
  937.     /* make tree out of our list */
  938.     tree_init(&mytree);
  939.  
  940.     /* set global variables for TreeSortUserCompare and TransferNode's use */    
  941.     nForTreeSortUseOnly = nThisSortType;   /* Used by TreeSortUserCompare  */
  942.     lForTreeSortUseOnly = thislist;          /* Used by TransferNode         */
  943.     
  944.     lTreeTicker = 0;
  945.     lTreeSubTicker = 0;
  946.     
  947.     while (CurrentNode != NULL)
  948.     {        
  949.         if (CurrentNode->ln_Succ != NULL)    /* This is necessary to avoid the "killer node" ??? */
  950.             tree_add(&mytree, TreeSortUserCompare, (char *) CurrentNode, DeleteNodeError);
  951.     
  952.         CurrentNode = CurrentNode->ln_Succ;        /* move down the list */
  953.     }
  954.  
  955.     /* traverse tree, inserting into new list */
  956.     /* nAbort now stays true only if both of the below are true */
  957.     if (tree_trav(&mytree,TransferNode) == FALSE)
  958.         MakeReq("Tree Sort Error","Warning:  Tree Sort failed; list may be incomplete", "Uh-Oh");
  959.     
  960.     /* now clean up the tree -- since Nodes are still in a List, we don't want to delete them */
  961.      tree_mung(&mytree, DoNothing);
  962. }    
  963.  
  964.  
  965.  
  966. int DoNothing (struct Node *thisnode)
  967. {
  968.    /* and here is the magic code to .... do nothing! */
  969.    return(0);
  970. }
  971.  
  972.  
  973.  
  974.  
  975.  
  976. int TransferNode(struct Node *thisnode)
  977. {    
  978.     if (isAminetParsable(thisnode->ln_Name))
  979.     {
  980.         Remove(thisnode); 
  981.         AddTail((struct List *) lForTreeSortUseOnly, thisnode); 
  982.     }
  983.     return(TRUE);
  984. }
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991. int PrintNodeData(struct Node *thisnode)
  992. {
  993.  
  994.     if (thisnode == NULL) 
  995.     {
  996.         printf("PND:  called with thisnode == NULL!\n");
  997.         return(FALSE);
  998.     }
  999.     if (thisnode->ln_Name == NULL) 
  1000.     {
  1001.         printf("PND:  called with thisnode->ln_Name == NULL!\n");
  1002.         return(FALSE);
  1003.     }
  1004.     
  1005.     printf("[%s]\n",thisnode->ln_Name);
  1006.     return(TRUE);
  1007. }
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014. int DeleteNodeError(struct Node *thisnode)
  1015. {
  1016.     printf("tree_add tried to delete this node:\n");
  1017.     PrintNodeData(thisnode);
  1018. }
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025. void BubbleSortList(struct List *thislist, int nThisSortType, char *sSortWinString, char *sSortTypeString)
  1026. {
  1027.    /* a simple swap-sort */
  1028.     int nSwappedThisPass = 1, nUpdateTitle = 0, nUpdateCount = 0;
  1029.     struct Node *current, *past;
  1030.  
  1031.     while (nSwappedThisPass > 0)
  1032.     {
  1033.         /* start a pass */
  1034.         past = thislist->lh_Head;
  1035.         if (past == NULL) return;
  1036.         
  1037.         current = past->ln_Succ;
  1038.         nSwappedThisPass = 0;        /* start with none recorded */
  1039.  
  1040.         while (current != NULL)            
  1041.         {
  1042.             /* Only sort if this is an Aminet file line, or not an Aminet Sort */    
  1043.             if ((current->ln_Name != NULL)&&(past->ln_Name != NULL)&&
  1044.                 (isAminetParsable(current->ln_Name)&&isAminetParsable(past->ln_Name)))
  1045.             {
  1046.                 if ((nThisSortType == SORTBYDIR) &&(CompareByDir (past,current) > 0) ||
  1047.                     (nThisSortType == SORTBYSIZE)&&(CompareBySize(past,current) > 0) ||
  1048.                     (nThisSortType == SORTBYDESC)&&(CompareByDesc(past,current) > 0) ||
  1049.                     (nThisSortType == SORTBYNAME)&&(CompareByName(past,current) > 0))
  1050.                 {
  1051.                     /* Swap the two nodes */
  1052.                      Remove(past);
  1053.                      Insert(thislist, past, current);
  1054.                      nSwappedThisPass++;
  1055.                 }
  1056.             }    
  1057.             past = current;
  1058.             current = current->ln_Succ;
  1059.         }
  1060.         
  1061.         if (windowisopen)
  1062.         {
  1063.             sprintf(sSortWinString,"%i",nUpdateCount);
  1064.             SetWindowTitles(mgetWnd, sSortTypeString, (char *) ~0);
  1065.             nUpdateCount++; 
  1066.          }              
  1067.     }        
  1068.     return;
  1069. }
  1070.         
  1071.  
  1072. /* Returns the length of the first "word" in the string, i.e. number
  1073.    of letters before the space */        
  1074. int LengthOfWord(char *szString)
  1075. {
  1076.     char *pcTemp = szString;
  1077.     int nCount = 0;
  1078.     
  1079.     /* skip any leading spaces */
  1080.     while (*pcTemp == ' ') pcTemp++;
  1081.     
  1082.     /* Count chars in word */    
  1083.     while ((*pcTemp != '\0')&&(*pcTemp != ' ')) 
  1084.     {
  1085.         nCount++;
  1086.         pcTemp++;
  1087.     }
  1088.     
  1089.     return(nCount);
  1090. }
  1091.  
  1092.  
  1093.  
  1094.  
  1095. int OutputList(struct List *thislist)
  1096. {
  1097. #define LASTDIRBUFSIZE 30
  1098.  
  1099.  char *p;
  1100.  int k,l,z,next_bytes,putnameOK = 0,putcommandOK = 1; 
  1101.  int printed_bytes = maxoutputlinelength - 1, printreturnfirst = 0;
  1102.  char outname[MAXFILELINELENGTH],szLastDir[LASTDIRBUFSIZE];
  1103.  struct Node *current;
  1104.  
  1105.  memset(szLastDir,NUL,LASTDIRBUFSIZE);
  1106.  
  1107.  /* Get any readme files first, so user can browse them while d/l'ing the rest */
  1108.  if (getreadmes)
  1109.     {
  1110.     current = thislist->lh_Head;
  1111.      while (current != NULL)
  1112.      {
  1113.          /* watch out for empty nodes! */
  1114.         if (isAminetParsable(current->ln_Name))
  1115.         {
  1116.             z = strlen(current->ln_Name);
  1117.             /* Extra filtering code, borrowed from mgetlistviewclicked()... */
  1118.             if ((current->ln_Name[nNameCol] < '0')||(current->ln_Name [nNameCol] > 'z')) z = 0;
  1119.             if (current->ln_Name[nDirCol] < '0') z = 0;
  1120.             if ((filesflag == 0)&&(current->ln_Name[nPlusCol] != '+')) z = 0;
  1121.             /* end code from mgetlistviewclicked() ... */
  1122.         }
  1123.         else z=0;
  1124.         
  1125.         if (z>nDirCol)
  1126.         {
  1127.             k = LengthOfWord(¤t->ln_Name[nNameCol]);    /* length of filename */
  1128.             l = LengthOfWord(¤t->ln_Name[nDirCol]);   /* length of directory */
  1129.     
  1130.             if ((k<(nDirCol+1))&&(k>0)&&(l<12)&&(l>2))
  1131.             {
  1132.                 memset(outname,NUL,MAXFILELINELENGTH);
  1133.                 strncat(outname,¤t->ln_Name[nDirCol],l);
  1134.                 
  1135.                 /* Here we have the directory name--see if it's different, generate cd */
  1136.                 if ((current->ln_Name[nPlusCol] == '+')&&
  1137.                     (nocd == 0)&&
  1138.                     (simplepaths == 1)&&
  1139.                     (strncmp(szLastDir,outname,LASTDIRBUFSIZE) != 0)) 
  1140.                 {
  1141.                     memset(szLastDir,NUL,LASTDIRBUFSIZE);
  1142.                     GenerateCDCommand(&printreturnfirst, &printed_bytes, szLastDir, outname);
  1143.                     putnameOK = 1;
  1144.                     putcommandOK = 0;
  1145.                 }
  1146.                 
  1147.                 if (simplepaths == 1)
  1148.                 {    
  1149.                     /* remove path so it won't be printed again in the mget command */
  1150.                     memset(outname,NUL,sizeof(outname));
  1151.                 }
  1152.                 else
  1153.                 {
  1154.                     strncat(outname,"/",1);
  1155.                 }
  1156.                 
  1157.                 strncat(outname,¤t->ln_Name[nNameCol],k);
  1158.                 outname[79]=0;    /* just in case, we'll reterminate the string */            
  1159.             
  1160.                 if (current->ln_Name[nPlusCol] == '+')
  1161.                     {    
  1162.                     /* find the last '.' in outname, and change whatever's after it to 'readme'! */
  1163.                     p = strrchr(outname,'.');
  1164.                     
  1165.                     /* and if there is no "." ? */
  1166.                     if (p == NULL)
  1167.                     {
  1168.                         strcat(outname,".");
  1169.                         p = strrchr(outname,'.');
  1170.                     }
  1171.                     
  1172.                     strcpy(p+1,"readme");
  1173.                     
  1174.                     next_bytes = strlen(outname) + 1;    /* + 1 for the space */
  1175.                     if ((next_bytes>3)&&(next_bytes<39))
  1176.                         {
  1177.                         if ((putcommandOK == 1)&&(!nosplit)&&((printed_bytes + next_bytes) > maxoutputlinelength))
  1178.                             {
  1179.                             PrintCommandString(&printreturnfirst, &printed_bytes);            
  1180.                             putnameOK = 1;
  1181.                             }            
  1182.                         fprintf(fpOut,"%s ",outname);
  1183.                         printed_bytes = printed_bytes + next_bytes;
  1184.                         putcommandOK = 1;
  1185.                         }
  1186.                     }
  1187.                 }
  1188.             }
  1189.         current = current->ln_Succ;    
  1190.         }
  1191.     }        
  1192.  
  1193.  if (filesflag)
  1194.  {    
  1195.      current = thislist->lh_Head;    
  1196.     while (current != NULL)
  1197.     {
  1198.          /* watch out for empty nodes! */
  1199.         if (isAminetParsable(current->ln_Name))
  1200.         {
  1201.             z = strlen(current->ln_Name);
  1202.             /* Extra filtering code, borrowed from mgetlistviewclicked()... */
  1203.             if ((current->ln_Name[nNameCol] < '0')||(current->ln_Name [nNameCol] > 'z')) z = 0;
  1204.             if ((filesflag == 0)&&(current->ln_Name[nPlusCol] != '+')) z = 0;
  1205.             /* end code from mgetlistviewclicked() ... */
  1206.         }
  1207.         else z=0;
  1208.  
  1209.         if (z>nDirCol)
  1210.         {
  1211.             k = LengthOfWord(¤t->ln_Name[nNameCol]);    /* length of filename */
  1212.             l = LengthOfWord(¤t->ln_Name[nDirCol]);   /* length of directory */
  1213.  
  1214.             if ((k<(nDirCol+1))&&(k>0)&&(l<12)&&(l>2))
  1215.             {
  1216.                 memset(outname,NUL,MAXFILELINELENGTH);
  1217.                 strncat(outname,¤t->ln_Name[nDirCol],l);
  1218.  
  1219.                 /* Here we have the directory name--see if it's different, generate cd */
  1220.                 if ((nocd == 0)&&
  1221.                     (simplepaths == 1)&&
  1222.                     (strncmp(szLastDir,outname,LASTDIRBUFSIZE) != 0)) 
  1223.                 {
  1224.                     memset(szLastDir,NUL,LASTDIRBUFSIZE);
  1225.                     GenerateCDCommand(&printreturnfirst, &printed_bytes, szLastDir, outname);
  1226.                     putcommandOK = 0;
  1227.                     putnameOK = 1;
  1228.                 }
  1229.                 
  1230.                 if (simplepaths == 1)
  1231.                 {    
  1232.                     /* remove path so it won't be printed again in the mget command */
  1233.                     memset(outname,NUL,sizeof(outname));
  1234.                 }
  1235.                 else
  1236.                 {
  1237.                     strncat(outname,"/",1);
  1238.                 }
  1239.                 
  1240.                 
  1241.                 strncat(outname,¤t->ln_Name[nNameCol],k);
  1242.                 outname[79]=0;    /* just in case, we'll reterminate the string */            
  1243.                 if (filesflag)
  1244.                 {    
  1245.                     next_bytes = strlen(outname) + 1;    /* + 1 for the space */
  1246.                     if ((next_bytes>3)&&(next_bytes<33))
  1247.                     {
  1248.                         if ((putcommandOK == 1)&&(!nosplit)&&((printed_bytes + next_bytes) > maxoutputlinelength))
  1249.                         {
  1250.                             PrintCommandString(&printreturnfirst, &printed_bytes);    
  1251.                             putnameOK = 1;
  1252.                         }            
  1253.                         fprintf(fpOut,"%s ",outname);
  1254.                         putcommandOK = 1;
  1255.                         printed_bytes = printed_bytes + next_bytes;
  1256.                     }
  1257.                 }
  1258.             }
  1259.         }    
  1260.     current = current->ln_Succ;    
  1261.     }
  1262.  }
  1263. return(1);
  1264. }
  1265.  
  1266.  
  1267.  
  1268.  
  1269. void PrintCommandString(int *printreturnfirst, int *printed_bytes)
  1270. {
  1271.     if (*printreturnfirst) fprintf(fpOut,sEndOfLineString); 
  1272.     *printreturnfirst = 1;
  1273.         
  1274.     if (nocommand) 
  1275.     {
  1276.         *printed_bytes = 0;
  1277.     }
  1278.     else
  1279.     {
  1280.         fprintf(fpOut,"%s",szCommandString);
  1281.         *printreturnfirst = 1;
  1282.         *printed_bytes = strlen(szCommandString) + 1;    /* reset counter for next batch */
  1283.     }
  1284.     return;
  1285. }
  1286.  
  1287.  
  1288.  
  1289.  
  1290. void GenerateCDCommand(int *printreturnfirst, int *printed_bytes, char *szLastDir, char *outname)
  1291. {
  1292.     if (*printreturnfirst) fprintf(fpOut,sEndOfLineString);
  1293.     fprintf(fpOut,"cd ");
  1294.                 
  1295.     /* On the first item, we will be starting at the aminet root
  1296.        directory, so we won't need to print the ../.. .  After that,
  1297.         though, we will.  printreturnfirst serves nicely to tell
  1298.         whether or not we're in the first iteration. */   
  1299.     
  1300.     if (*printreturnfirst == 1) fprintf(fpOut,sAminetPathString);
  1301.             
  1302.     fprintf(fpOut,"%s",outname);
  1303.     *printreturnfirst = 1;
  1304.     PrintCommandString(printreturnfirst, printed_bytes);
  1305.  
  1306.     /* update buffer */    
  1307.     strncpy(szLastDir,outname,30);    
  1308.  
  1309.     return;
  1310. }            
  1311.  
  1312.  
  1313.  
  1314. int RawOutputList(struct List *thislist)
  1315. {
  1316. struct Node *current = thislist->lh_Head;
  1317. int minlinelength = 1;
  1318.  
  1319.  if (keepblanklines == 1) minlinelength = 0;
  1320.       
  1321.  while (current != NULL)
  1322.     {    
  1323.     if ((current->ln_Name != NULL)&&(current->ln_Name[0] < 128)&&(strlen(current->ln_Name) >= minlinelength))
  1324.         {
  1325.             if (current->ln_Name[0] < 14) 
  1326.             {
  1327.                 fprintf(fpOut,"\n",current->ln_Name);
  1328.             }
  1329.             else
  1330.             {
  1331.                 fprintf(fpOut,"%.300s\n",current->ln_Name);
  1332.             }
  1333.         }
  1334.     current = current->ln_Succ;
  1335.     }
  1336. return(1);
  1337. }
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347. int MakeReq(char *sText, char *sTitle, char *sGadgets)
  1348. {
  1349.     struct EasyStruct myreq;
  1350.     LONG number = 0L;
  1351.     int nResult;
  1352.     char sDefaultTitle[] = "GadMGet Error";
  1353.     
  1354.     if (sTitle == NULL) sTitle = sDefaultTitle;
  1355.     if (sText == NULL) sText = sDefaultTitle;
  1356.     if (sGadgets == NULL) sGadgets = "OK";
  1357.     
  1358.     myreq.es_TextFormat   = sText;
  1359.     myreq.es_Title        = sTitle;
  1360.     myreq.es_GadgetFormat = sGadgets;
  1361.     
  1362.     if (mgetWnd != NULL) SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1363.     nResult = EasyRequest(mgetWnd, &myreq, NULL, NULL, number);
  1364.     if (mgetWnd != NULL) ClearPointer(mgetWnd);
  1365.     return(nResult);
  1366. }
  1367.  
  1368.  
  1369. int mgettreesort (VOID)
  1370. {
  1371.     nSortAlgorithm = TREESORT;
  1372.     SetMenuValues();
  1373. }
  1374.  
  1375. int mgetbubblesort (VOID)
  1376. {
  1377.     nSortAlgorithm = BUBBLESORT;
  1378.     SetMenuValues();
  1379. }    
  1380.  
  1381. int mgetsortcase (VOID)
  1382. {
  1383.     sortcasesensitive = Not[sortcasesensitive];
  1384.     if (nKeepSorted[0] == 1) SortList(filelist,nSortType[0]);
  1385.     if (nKeepSorted[1] == 1) SortList(getlist, nSortType[1]);
  1386.     SetMenuValues();
  1387. }
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396. int mgetabout (VOID)
  1397. {
  1398.     char sAboutText[100];
  1399.  
  1400.     strcpy(sAboutText,pnamestring);
  1401.     strcat(sAboutText,"\n\nby Jeremy Friesner\njfriesne@ucsd.edu\n");
  1402.     MakeReq(sAboutText,"About GadMGet","Hey, Cool!");
  1403.     return(1);
  1404. }
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413. int mgetquit (VOID)
  1414. {
  1415.     done=TRUE;
  1416. }
  1417.  
  1418.  
  1419.  
  1420.  
  1421. int mgetmultiselect(VOID)
  1422. {
  1423. int lin, nSortAtEnd = FALSE;
  1424. struct Node *select_current = filelist->lh_Head, *select_next = NULL;
  1425. char sUpperBuffer[MAXFILELINELENGTH],sUpperSearchString[MAXFILELINELENGTH];
  1426.  
  1427. requesttype = SELECT_REQUESTTYPE;       /* This is a HORRIBLE way to program, but I don't want  */
  1428. lin = mgetfind();                                /* to try to change the parameters since it might screw */
  1429. requesttype = FIND_REQUESTTYPE;            /* up the mget_listview2 functions...                        */
  1430.  
  1431.  if (lin == TRUE) 
  1432.  {
  1433.     SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1434.      GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  1435.     GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  1436.         
  1437.     if (searchcasesensitive)    
  1438.     {            
  1439.         while (select_current != NULL)
  1440.         {
  1441.             if ((nKeepSorted[1] == TRUE)&&(getlist_length > 240))
  1442.             {
  1443.                   nSortAtEnd = TRUE;                        /* remember to sort when done */
  1444.                   nKeepSorted[1] = FALSE;
  1445.             }       
  1446.  
  1447.             if ((select_current->ln_Name != NULL)&&
  1448.                 (strstr(select_current->ln_Name,sMultiSelect) != 0))
  1449.             {
  1450.                 select_next = select_current->ln_Succ;
  1451.                 TransferToSelected(select_current);
  1452.                 select_current = select_next;
  1453.             }
  1454.             else
  1455.             {
  1456.                 select_current = select_current->ln_Succ; 
  1457.             }
  1458.         }
  1459.     }
  1460.     else
  1461.     {
  1462.         strncpy(sUpperSearchString,sMultiSelect,sizeof(sUpperSearchString));
  1463.         UpperCase(sUpperSearchString);
  1464.         while (select_current != NULL)
  1465.         {
  1466.             if ((nKeepSorted[1] == TRUE)&&(getlist_length > 240))
  1467.             {
  1468.                   nSortAtEnd = TRUE;                        /* remember to sort when done */
  1469.                   nKeepSorted[1] = FALSE;
  1470.             }       
  1471.  
  1472.             if (select_current->ln_Name != NULL)
  1473.             {
  1474.                 strncpy(sUpperBuffer,select_current->ln_Name,sizeof(sUpperBuffer)-1);
  1475.                 UpperCase(sUpperBuffer);
  1476.  
  1477.                 if (strstr(sUpperBuffer,sUpperSearchString) != 0)
  1478.                 {
  1479.                     select_next = select_current->ln_Succ;
  1480.                     TransferToSelected(select_current);
  1481.                     select_current = select_next;
  1482.                 }
  1483.                 else
  1484.                 {
  1485.                     select_current = select_current->ln_Succ; 
  1486.                 }
  1487.             }
  1488.             else
  1489.             {
  1490.                     select_current = select_current->ln_Succ; 
  1491.             }
  1492.         }
  1493.     }
  1494.  
  1495.  if (nSortAtEnd == TRUE)
  1496.  {
  1497.      mgetgetkeep();        /* Sort files now, at the end */
  1498.  }
  1499.  
  1500.  GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
  1501.  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  1502.  
  1503.  ChangeWindowTitle();
  1504.  ClearPointer(mgetWnd);
  1505.  }
  1506. }
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512. int mgetmultideselect(VOID)
  1513. {
  1514. int lin, nSortAtEnd = FALSE;
  1515. struct Node *select_current = getlist->lh_Head, *select_next = NULL;
  1516. char sUpperBuffer[MAXFILELINELENGTH], sUpperSearchString[MAXFILELINELENGTH];
  1517.  
  1518. requesttype = DESELECT_REQUESTTYPE;       /* This is a HORRIBLE way to program, but I don't want  */
  1519. lin = mgetfind();                                /* to try to change the parameters since it might screw */
  1520. requesttype = FIND_REQUESTTYPE;            /* up the mget_listview2 functions...                        */
  1521.  
  1522. if (lin == TRUE) 
  1523.  {
  1524.      SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1525.      GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  1526.     GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  1527.  
  1528.     if (searchcasesensitive)    
  1529.     {
  1530.         while (select_current != NULL)
  1531.         {
  1532.            if ((nKeepSorted[0] == TRUE)&&(filelist_length > 240))
  1533.             {
  1534.                  nSortAtEnd = TRUE;                        /* remember to sort when done */
  1535.                   nKeepSorted[0] = FALSE;
  1536.             }
  1537.  
  1538.             if ((select_current->ln_Name != NULL)&&
  1539.                 (strstr(select_current->ln_Name,sMultiSelect) != 0))
  1540.             {
  1541.                 select_next = select_current->ln_Succ;
  1542.                 TransferToFiles(select_current);
  1543.                 select_current = select_next;
  1544.             }
  1545.             else
  1546.             {
  1547.                 select_current = select_current->ln_Succ; 
  1548.             }
  1549.         }
  1550.     }
  1551.     else
  1552.     {
  1553.         strncpy(sUpperSearchString,sMultiSelect,sizeof(sUpperSearchString));
  1554.         UpperCase(sUpperSearchString);
  1555.         while (select_current != NULL)
  1556.         {
  1557.            if ((nKeepSorted[0] == TRUE)&&(filelist_length > 240))
  1558.             {
  1559.                  nSortAtEnd = TRUE;                        /* remember to sort when done */
  1560.                   nKeepSorted[0] = FALSE;
  1561.             }
  1562.  
  1563.             if (select_current->ln_Name != NULL)
  1564.             {
  1565.                 strncpy(sUpperBuffer,select_current->ln_Name,sizeof(sUpperBuffer)-1);
  1566.                 UpperCase(sUpperBuffer);
  1567.  
  1568.                 if (strstr(sUpperBuffer,sUpperSearchString) != 0)
  1569.                 {
  1570.                     select_next = select_current->ln_Succ;
  1571.                     TransferToFiles(select_current);
  1572.                     select_current = select_next;
  1573.                 }
  1574.                 else
  1575.                 {
  1576.                     select_current = select_current->ln_Succ; 
  1577.                 }
  1578.             }
  1579.             else
  1580.             {
  1581.                     select_current = select_current->ln_Succ; 
  1582.             }
  1583.         
  1584.         }
  1585.     }
  1586.  
  1587.  if (nSortAtEnd == TRUE)
  1588.  {
  1589.      mgetfileskeep();        /* Sort files now, at the end */
  1590.  }
  1591.  
  1592.  GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
  1593.  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  1594.  
  1595.  ChangeWindowTitle();
  1596.  ClearPointer(mgetWnd);
  1597.  }
  1598. }
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604. int mgetcase (VOID)
  1605. {
  1606. searchcasesensitive = Not[searchcasesensitive];
  1607. SetMenuValues();
  1608. }
  1609.  
  1610.  
  1611.  
  1612.  
  1613. int mgetCD (VOID)
  1614. {
  1615. simplepaths = Not[simplepaths];
  1616. SetMenuValues();
  1617. }
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624. int mgetfindtop (VOID)
  1625. {
  1626.     mgetfind_findtype = SEARCHTYPE_TOP;
  1627.     mgetfind();
  1628.     mgetfind_findtype = SEARCHTYPE_FORWARD;
  1629.     return(TRUE);
  1630. }
  1631.  
  1632.  
  1633.  
  1634. int mgetfindbottom (VOID)
  1635. {
  1636.     mgetfind_findtype = SEARCHTYPE_BOTTOM;
  1637.     mgetfind();
  1638.     mgetfind_findtype = SEARCHTYPE_FORWARD;
  1639.     return(TRUE);
  1640. }
  1641.  
  1642.  
  1643. int mgetfindback (VOID)
  1644. {
  1645.     mgetfind_findtype = SEARCHTYPE_BACKWARD;
  1646.     mgetfind();
  1647.     mgetfind_findtype = SEARCHTYPE_FORWARD;
  1648.     return(TRUE);
  1649. }
  1650.  
  1651.  
  1652. int mgetfind (VOID)
  1653. {
  1654. ULONG winsig, signals;
  1655. int done = 0, found = 0, index = -1;
  1656. int fwindowwidth = 450, fwindowheight = 35 + Scr->RastPort.TxHeight;
  1657. int fwindowleft = (mgetLeft + (windowwidth/2) - (fwindowwidth/2));
  1658. int fwindowtop  = (mgetTop  + (windowheight/2)- (fwindowheight/2));
  1659. int WindowHeightLines = nTopListHeight/(listfont.ta_YSize);
  1660. struct NewGadget stringGad;
  1661. struct IntuiMessage *imsg;
  1662. struct Gadget *newgad = NULL;
  1663. char numstring[100], *ss = searchstring, sTempOutString[300];
  1664. char *wp = NULL,windowtitlestring0[] = "Search Window", 
  1665.                 windowtitlestring1[] = "Line Length Window",
  1666.                 windowtitlestring2[] = "Output File Change Window",
  1667.                 windowtitlestring3[] = "Select Multiple Items Window",
  1668.                 windowtitlestring4[] = "Deselect Multiple Items Window";
  1669. FILE *fpTemp = NULL;
  1670.  
  1671. findvi  = GetVisualInfo(Scr, TAG_END);
  1672. if (findvi == NULL) return(0);
  1673. if (findwindow != NULL) return(0);
  1674.  
  1675.  
  1676. if (fwindowleft < 0) fwindowleft = mgetLeft;
  1677. if (fwindowheight < 0) fwindowtop = mgetTop;
  1678.  
  1679.  newgad = CreateContext(&findgadlist);
  1680.  if (newgad == 0)
  1681.     {
  1682.     MakeReq("Couldn't create findwindow gad context!\n",NULL,"Dammit!");
  1683.     return(0);
  1684.     }
  1685.  
  1686.  if (newgad == NULL) return(0);
  1687.  
  1688. stringGad.ng_TextAttr     = &topaz8;    /* Cant figure out how to get system default into a TextAttr!  No name string available! */
  1689. stringGad.ng_VisualInfo  = findvi;
  1690. stringGad.ng_LeftEdge     = 5;
  1691. stringGad.ng_TopEdge        = 18 + Scr->RastPort.TxHeight;
  1692. stringGad.ng_Width         = (fwindowwidth-10);
  1693. stringGad.ng_Height         = 13;
  1694. stringGad.ng_GadgetText  = "Please enter search string.";
  1695. stringGad.ng_GadgetID     = 35;    
  1696. stringGad.ng_Flags         = PLACETEXT_ABOVE;
  1697.  
  1698.  switch (requesttype)
  1699.  {
  1700.      case FIND_REQUESTTYPE:
  1701.         wp = windowtitlestring0;
  1702.    break;
  1703.  
  1704.    case LINELENGTH_REQUESTTYPE:
  1705.          wp = windowtitlestring1;
  1706.          stringGad.ng_GadgetText = "Please enter new maximum line length.";
  1707.          sprintf(numstring,"%i\0",maxoutputlinelength);    
  1708.          ss = numstring;
  1709.    break;
  1710.    
  1711.    case OUTPUTFILE_REQUESTTYPE:
  1712.          wp = windowtitlestring2;
  1713.          stringGad.ng_GadgetText = "Please enter new output file path/device.";
  1714.          sprintf(numstring,"%s",sOutFileName);
  1715.          strncpy(sTempOutString,sOutFileName,sizeof(sTempOutString));
  1716.          ss = sTempOutString;
  1717.    break;
  1718.    
  1719.    case SELECT_REQUESTTYPE:
  1720.        wp = windowtitlestring3;
  1721.        stringGad.ng_GadgetText = "Please enter key string to select files with.";
  1722.        sprintf(numstring,"%s",sMultiSelect);
  1723.          strncpy(sTempOutString,sMultiSelect,sizeof(sTempOutString));
  1724.          ss = sTempOutString;       
  1725.    break;
  1726.    
  1727.    case DESELECT_REQUESTTYPE:
  1728.        wp = windowtitlestring4;
  1729.        stringGad.ng_GadgetText = "Please enter key string to deselect files with.";
  1730.        sprintf(numstring,"%s",sMultiSelect);
  1731.        strncpy(sTempOutString,sMultiSelect,sizeof(sTempOutString));
  1732.        ss = sTempOutString;
  1733.       break;
  1734.  }
  1735.  
  1736.  
  1737.  newgad = CreateGadget(STRING_KIND, newgad, &stringGad, 
  1738.                   GTST_String, ss, 
  1739.                   STRINGA_Justification, GACT_STRINGCENTER, 
  1740.                   GA_Immediate, TRUE,
  1741.                   TAG_END);  
  1742.  
  1743.  if (newgad == NULL) 
  1744.     {
  1745.     FreeGadgets(findgadlist);
  1746.     FreeVisualInfo(findvi);
  1747.     return(0);
  1748.     }
  1749.  
  1750.  if (GadToolsBase->lib_Version == 37)
  1751.     {
  1752.     /* Only do it the "illegal" way under v37.  GA_Immediate in the CreateGadget
  1753.        line, above, won't work under v37 but will on later releases. */
  1754.     newgad->Activation |= GACT_IMMEDIATE; 
  1755.     }    
  1756.  
  1757.  switch (screentype)
  1758.     {
  1759.     case USE_PUBSCREEN:
  1760.         findwindow = OpenWindowTags(NULL,
  1761.                 WA_Left,        fwindowleft,
  1762.                 WA_Top,        fwindowtop,
  1763.                 WA_Width,         fwindowwidth,
  1764.                 WA_Height,    fwindowheight,
  1765.                 WA_PubScreen,    Scr,
  1766.                 WA_PubScreenFallBack, TRUE,
  1767.                 WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|
  1768.                             IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  1769.                 WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  1770.                 WA_Gadgets,    findgadlist,
  1771.                 WA_Title,         wp,
  1772.                 WA_ScreenTitle,    pnamestring,
  1773.                 TAG_DONE );
  1774.         break;
  1775.     case USE_CUSTOMSCREEN:
  1776.         findwindow = OpenWindowTags(NULL,
  1777.                 WA_Left,        fwindowleft,
  1778.                 WA_Top,        fwindowtop,
  1779.                 WA_Width,         fwindowwidth,
  1780.                 WA_Height,    fwindowheight,
  1781.                 WA_CustomScreen, Scr,
  1782.                 WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|
  1783.                             IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  1784.                 WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  1785.                 WA_Gadgets,    findgadlist,
  1786.                 WA_Title,         wp,
  1787.                 WA_ScreenTitle,    pnamestring,
  1788.                 WA_CustomScreen,    Scr,
  1789.                 TAG_DONE );
  1790.         break;
  1791.     case USE_WBSCREEN:
  1792.         findwindow = OpenWindowTags(NULL,
  1793.                 WA_Left,        fwindowleft,
  1794.                 WA_Top,        fwindowtop,
  1795.                 WA_Width,         fwindowwidth,
  1796.                 WA_Height,    fwindowheight,
  1797.                 WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|
  1798.                             IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  1799.                 WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  1800.                 WA_Gadgets,    findgadlist,
  1801.                 WA_Title,         wp,
  1802.                 WA_ScreenTitle,    pnamestring,
  1803.                 TAG_DONE );
  1804.         break;
  1805.     }
  1806.  
  1807. if (findwindow == NULL) return(0);
  1808. GT_RefreshWindow(findwindow, NULL); 
  1809.  
  1810. SetWindowTitles(mgetWnd, "MGet window inactive--close daughter window to continue", (char *) ~0); 
  1811. SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1812.  
  1813. winsig = 1 << findwindow->UserPort->mp_SigBit;
  1814.  
  1815.  while (!done)
  1816.     {
  1817.     signals = Wait(winsig);
  1818.     if (signals&winsig)
  1819.         {
  1820.         while ((!done) && (imsg = GT_GetIMsg(findwindow->UserPort)))
  1821.             {
  1822.             
  1823.             switch(imsg->Class)
  1824.                 {            
  1825.                 case IDCMP_ACTIVEWINDOW:
  1826.                     ActivateGadget(newgad,findwindow,NULL);
  1827.                     break;
  1828.                         
  1829.                 case IDCMP_GADGETUP:
  1830.                     strncpy(ss,((struct StringInfo*)newgad->SpecialInfo)->Buffer,sizeof(searchstring));
  1831.                     done = 1;
  1832.                     break;
  1833.         
  1834.                 case IDCMP_CLOSEWINDOW:
  1835.                     done = 2;
  1836.                     break;
  1837.                     
  1838.                 case IDCMP_REFRESHWINDOW:
  1839.                     GT_BeginRefresh(findwindow);
  1840.                     GT_EndRefresh(findwindow, TRUE);
  1841.                     break;
  1842.                 }
  1843.             GT_ReplyIMsg(imsg);
  1844.             }
  1845.         }
  1846.     }
  1847.     
  1848. CloseWindow(findwindow);
  1849. FreeGadgets(findgadlist);
  1850. FreeVisualInfo(findvi); 
  1851. findwindow = NULL;
  1852.  
  1853. ClearPointer(mgetWnd);
  1854. ChangeWindowTitle();  /* just in case */
  1855.  
  1856.  if ((requesttype == SELECT_REQUESTTYPE)||(requesttype == DESELECT_REQUESTTYPE))
  1857.  {
  1858.      if (strlen(sTempOutString) == 0) return(FALSE);  /* empty string = abort, don't move any items */
  1859.     strncpy(sMultiSelect,sTempOutString,sizeof(sMultiSelect));
  1860.      ChangeWindowTitle();
  1861.      return(TRUE);
  1862.  }
  1863.  
  1864.  if (requesttype == LINELENGTH_REQUESTTYPE) 
  1865.  {
  1866.         ChangeWindowTitle();    
  1867.         return(atoi(ss));
  1868.  }
  1869.  
  1870.  if (requesttype == OUTPUTFILE_REQUESTTYPE)
  1871.     {
  1872.         if (strlen(sTempOutString) == 0)
  1873.         {
  1874.             if (BStartedFromWB == FALSE)
  1875.             {
  1876.                 fpOut = stdout;
  1877.                 *sOutFileName = '\0';    /* blank out filename string */
  1878.             }
  1879.             else
  1880.             {
  1881.                 strncpy(sTempOutString,"ram:GadMget.output",sizeof(sOutFileName));
  1882.             }
  1883.         }
  1884.         else
  1885.         {
  1886.             fpTemp = fopen(sTempOutString,"w");
  1887.             if (fpTemp == NULL)
  1888.             {
  1889.                 MakeReq("Couldn't open output file!\n",NULL,"Ok");
  1890.             }
  1891.             else
  1892.             {
  1893.                 fpOut = fpTemp;
  1894.                 strncpy(sOutFileName,sTempOutString,sizeof(sOutFileName));
  1895.                 fclose(fpTemp);
  1896.             }
  1897.         }
  1898.     ChangeWindowTitle();
  1899.     return(0);
  1900.     }
  1901.     
  1902.  if ((done == 2)||(strlen(searchstring) == 0))
  1903.     {
  1904.     ChangeWindowTitle();
  1905.     return(0);    /* can use searchstring now instead of ss */
  1906.     }            /* because we're no longer worried about the nums */
  1907.  
  1908. /* Now find it in the filelist */
  1909. index = SearchList(searchstring,mgetfind_findtype);
  1910. if (index == -1) DisplayBeep(Scr); else findgadgoto(index,3);
  1911. return(1);
  1912. }
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919. int mgetfindnext (VOID)
  1920. {
  1921. int next_index;
  1922.  
  1923. /* bump to next node */
  1924. next_index = SearchList(searchstring,SEARCHTYPE_NEXT);
  1925. if (next_index == -1) DisplayBeep(Scr); else findgadgoto(next_index,2);
  1926.  
  1927. return(TRUE);
  1928. }
  1929.  
  1930.  
  1931.  
  1932. int mgetfindprevious (VOID)
  1933. {
  1934. int prev_index;
  1935.  
  1936. /* bump to previous node */
  1937. prev_index = SearchList(searchstring,SEARCHTYPE_PREVIOUS);
  1938. if (prev_index == -1) DisplayBeep(Scr); else findgadgoto(prev_index,2);
  1939.  
  1940. return(TRUE);
  1941. }
  1942.  
  1943. int mgetfindcurrent (VOID)
  1944. {
  1945. if ((search_index == -1)||(search_current == NULL)) DisplayBeep(Scr); else findgadgoto(search_index,2);
  1946.  
  1947. return(TRUE);
  1948. }
  1949.  
  1950.  
  1951. int mgetfilesbydir (void)
  1952. {
  1953. nSortType[0] = SORTBYDIR;
  1954.  
  1955. SortList(filelist,nSortType[0]);
  1956. }
  1957.  
  1958.  
  1959. int mgetfilesbysize (void)
  1960. {
  1961. nSortType[0] = SORTBYSIZE;
  1962.  
  1963. SortList(filelist,nSortType[0]);
  1964. }
  1965.  
  1966.  
  1967. int mgetfilesbyname (void)
  1968. {
  1969. nSortType[0] = SORTBYNAME;
  1970.  
  1971. SortList(filelist,nSortType[0]);
  1972. }
  1973.  
  1974.  
  1975. int mgetfilesbydesc (void)
  1976. {
  1977. nSortType[0] = SORTBYDESC;
  1978.  
  1979. SortList(filelist,nSortType[0]);
  1980. }
  1981.  
  1982. int mgetfilesbyage (void)
  1983. {
  1984. nSortType[0] = SORTBYAGE;
  1985.  
  1986. SortList(filelist,nSortType[0]);
  1987. }
  1988.  
  1989.  
  1990. int mgetfileskeep (void)
  1991. {
  1992. if (nKeepSorted[0] == 1) 
  1993.     {
  1994.         nKeepSorted[0] = 0;
  1995.     }
  1996.     else
  1997.     {
  1998.         nKeepSorted[0] = 1;
  1999.         SortList(filelist,nSortType[0]);
  2000.     }
  2001. SetMenuValues();
  2002. }
  2003.  
  2004.  
  2005. int mgetgetbydir (void)
  2006. {
  2007. nSortType[1] = SORTBYDIR;
  2008.  
  2009. SortList(getlist,nSortType[1]);
  2010. }
  2011.  
  2012.  
  2013. int mgetgetbysize (void)
  2014. {
  2015. nSortType[1] = SORTBYSIZE;
  2016.  
  2017. SortList(getlist,nSortType[1]);
  2018. }
  2019.  
  2020.  
  2021. int mgetgetbyname (void)
  2022. {
  2023. nSortType[1] = SORTBYNAME;
  2024.  
  2025. SortList(getlist,nSortType[1]);
  2026. }
  2027.  
  2028.  
  2029. int mgetgetbydesc (void)
  2030. {
  2031. nSortType[1] = SORTBYDESC;
  2032.  
  2033. SortList(getlist,nSortType[1]);
  2034. }
  2035.  
  2036.  
  2037. int mgetgetbyage (void)
  2038. {
  2039. nSortType[1] = SORTBYAGE;
  2040.  
  2041. SortList(getlist,nSortType[1]);
  2042. }
  2043.  
  2044.  
  2045. int mgetgetkeep (void)
  2046. {
  2047. if (nKeepSorted[1] == TRUE) 
  2048.     {
  2049.         nKeepSorted[1] = FALSE;
  2050.     }
  2051.     else
  2052.     {
  2053.         nKeepSorted[1] = TRUE;
  2054.         SortList(getlist,nSortType[1]);
  2055.     }
  2056. SetMenuValues();
  2057. }
  2058.  
  2059.  
  2060.  
  2061.  
  2062.  
  2063. int SearchList(char *key, int nSearchType)
  2064. {
  2065. int found = 0, nTemp = 0, nSearchDir = SEARCH_FORWARD;
  2066. char sUpperBuffer[MAXFILELINELENGTH], sUpperSearchString[MAXFILELINELENGTH];
  2067.  
  2068. filelist->lh_Head->ln_Pred = NULL;    /* This should always be NULL, but is
  2069.                                                     sometimes set to a random value, causing
  2070.                                                     Enforcer hits whenever we traverse
  2071.                                                     Backwards.  So, we make sure.  */
  2072.  
  2073. /* keep a separate temporary search_* in case we fail */
  2074. int temp_search_index;
  2075. struct Node *temp_search_current;
  2076.  
  2077. SetWindowTitles(mgetWnd, "Searching...", (char *) ~0); 
  2078. SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  2079.  
  2080.  /* make sure search_current at least is *something* !! */
  2081.  if (search_current == NULL)
  2082.  {
  2083.     search_current = ListViewTopNode((struct Gadget *) mgetGadgets[0], filelist);
  2084.     search_index = ListViewTop((struct Gadget *) mgetGadgets[0], filelist);
  2085.  }
  2086.  
  2087. /* temporary copy */
  2088. temp_search_current = search_current;
  2089. temp_search_index = search_index;
  2090.     
  2091. /* Start at current top of display */
  2092. switch (nSearchType)
  2093. {
  2094.     case SEARCHTYPE_FORWARD:
  2095.         temp_search_current = ListViewTopNode((struct Gadget *) mgetGadgets[0], filelist);
  2096.         temp_search_index = ListViewTop((struct Gadget *) mgetGadgets[0], filelist);
  2097.         break;
  2098.  
  2099.     case SEARCHTYPE_BACKWARD:
  2100.         temp_search_current = ListViewTopNode((struct Gadget *) mgetGadgets[0], filelist);
  2101.         temp_search_index = ListViewTop((struct Gadget *) mgetGadgets[0], filelist);
  2102.         nSearchDir = SEARCH_BACKWARD;
  2103.         break;
  2104.         
  2105.     case SEARCHTYPE_NEXT:
  2106.         temp_search_current = temp_search_current->ln_Succ;
  2107.         temp_search_index++;
  2108.         break;
  2109.     
  2110.     case SEARCHTYPE_PREVIOUS:
  2111.         temp_search_current = temp_search_current->ln_Pred;
  2112.         temp_search_index--;
  2113.         nSearchDir = SEARCH_BACKWARD;
  2114.         break;
  2115.         
  2116.     case SEARCHTYPE_TOP:
  2117.         temp_search_current = filelist->lh_Head;
  2118.         temp_search_index = 0;
  2119.         break;
  2120.         
  2121.     case SEARCHTYPE_BOTTOM:
  2122.         temp_search_current = TailOf(filelist, &temp_search_index);
  2123.         nSearchDir = SEARCH_BACKWARD;
  2124.         break;        
  2125. }        
  2126.             
  2127.  
  2128. if (searchcasesensitive)    
  2129.     {
  2130.     while ((temp_search_current != NULL)&&(found == 0))
  2131.         {
  2132.         if ((temp_search_current->ln_Name != NULL)&&(strstr(temp_search_current->ln_Name,searchstring) != 0))
  2133.             found = 1;
  2134.             else
  2135.             {
  2136.                 if (nSearchDir == SEARCH_FORWARD)
  2137.                 {
  2138.                     temp_search_current = temp_search_current->ln_Succ; 
  2139.                     temp_search_index++;
  2140.                 }
  2141.                 else
  2142.                 {
  2143.                     temp_search_current = temp_search_current->ln_Pred; 
  2144.                     temp_search_index--;
  2145.                 }
  2146.             }
  2147.         }
  2148.     }
  2149.     else
  2150.     {
  2151.     strncpy(sUpperSearchString,key,sizeof(sUpperSearchString));
  2152.     UpperCase(sUpperSearchString);
  2153.     while ((temp_search_current != NULL)&&(found == 0))
  2154.         {
  2155.         if (temp_search_current->ln_Name != NULL)
  2156.             {
  2157.             strncpy(sUpperBuffer,temp_search_current->ln_Name,sizeof(sUpperBuffer)-1);
  2158.             UpperCase(sUpperBuffer);
  2159.             if (strstr(sUpperBuffer,sUpperSearchString) != 0)
  2160.                 found = 1;
  2161.             }
  2162.         if (found == 0)
  2163.             {
  2164.              if (nSearchDir == SEARCH_FORWARD)
  2165.                 {
  2166.                     temp_search_current = temp_search_current->ln_Succ; 
  2167.                     temp_search_index++;
  2168.                 }
  2169.                 else
  2170.                 {
  2171.                     temp_search_current = temp_search_current->ln_Pred; 
  2172.                     temp_search_index--;
  2173.                 }
  2174.             }
  2175.         }
  2176.     }
  2177.     
  2178. ChangeWindowTitle();
  2179. ClearPointer(mgetWnd);
  2180.  
  2181. if (found == 1) 
  2182. {    
  2183.     search_current = temp_search_current;        /* cast the temp copy in stone */
  2184.     search_index = temp_search_index;
  2185.     return(search_index); 
  2186. }
  2187. else 
  2188. {
  2189.     return(-1);
  2190. }
  2191.  
  2192. }
  2193.  
  2194.  
  2195.  
  2196.  
  2197.  
  2198.  
  2199.  
  2200.  
  2201.  
  2202.  
  2203.  
  2204. void findgadgoto (int index, int numberofflashes)
  2205. {
  2206. int i, xmin, ymin, xmax, ymax, ystep, midscreen;
  2207. int WindowHeightLines = nTopListHeight/(listfont.ta_YSize);
  2208. LONG yTop = 0;
  2209.  
  2210.  midscreen = index-(WindowHeightLines/2);
  2211.  if (midscreen < 0) midscreen = 0;
  2212.  
  2213.  GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, midscreen, TAG_END);
  2214.  yTop = ListViewTop((struct Gadget *) mgetGadgets[0], mgetWnd);
  2215.  ystep = index - yTop;
  2216.   
  2217.  xmin = Scr->WBorLeft + 4;
  2218.  ymin = (nTopListTop + ((listfont.ta_YSize) *ystep) + 2);
  2219.  xmax = windowwidth - Scr->WBorLeft - 20;
  2220.  ymax = ymin + (listfont.ta_YSize) - 1;
  2221.  
  2222.  SetDrMd(mgetWnd->RPort, 50); 
  2223.  for (i=0;i<numberofflashes;i++)
  2224.      {
  2225.      RectFill(mgetWnd->RPort,xmin,ymin,xmax,ymax);
  2226.      Delay(5);
  2227.      RectFill(mgetWnd->RPort,xmin,ymin,xmax,ymax);
  2228.      if (i<(numberofflashes-1)) Delay(5);
  2229.      }
  2230. }
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236. int ClearList(struct List *thislist)
  2237. {
  2238.     struct Node *current = thislist->lh_Head;
  2239.     struct Node *nextnode;
  2240.     const int nodesize = sizeof(struct Node);
  2241.  
  2242.     if (thislist == NULL) return(FALSE);
  2243.         
  2244.     while (current != NULL)
  2245.     {
  2246.         nextnode = current->ln_Succ;
  2247.         if (current->ln_Succ != NULL) 
  2248.         {
  2249.             Remove(current);
  2250.             if (current->ln_Name != NULL)
  2251.             {
  2252.                 FreeMem(current->ln_Name,current->ln_Pri+127);
  2253.                 added_bytes -= current->ln_Pri+127;
  2254.             }        
  2255.             FreeMem(current,nodesize);        added_bytes -= nodesize;
  2256.         }
  2257.         current = nextnode;
  2258.     }
  2259.     return(TRUE);
  2260. }
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267. int mgetclearfiles (void)
  2268. {
  2269.     /* prepare gadget for deletion */
  2270.     SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  2271.     GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  2272.  
  2273.     /* delete files list */
  2274.     ClearList(filelist);
  2275.     
  2276.     /* update window */
  2277.    GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  2278.    ChangeWindowTitle();
  2279.    ClearPointer(mgetWnd);    
  2280. }
  2281.  
  2282.  
  2283.  
  2284. int mgetclearget (void)
  2285. {
  2286.     /* prepare gadget for deletion */
  2287.     SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  2288.     GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  2289.  
  2290.     /* delete get list */
  2291.     ClearList(getlist);
  2292.  
  2293.     files_selected = 0;
  2294.     kbytes_selected = 0;
  2295.         
  2296.     /* update window */
  2297.    GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
  2298.    ChangeWindowTitle();
  2299.    ClearPointer(mgetWnd);    
  2300. }
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308. int mgetnoparse (void)
  2309. {
  2310. if (noparse) 
  2311.     {
  2312.     noparse = 0; 
  2313.     if (nKeepSorted[0] == 1) SortList(filelist,nSortType[0]);
  2314.     if (nKeepSorted[1] == 1) SortList(getlist, nSortType[1]);
  2315.     SetMenuValues();
  2316.     }
  2317.     else 
  2318.     {
  2319.     noparse = 1;        
  2320.     SetMenuValues();
  2321.     }
  2322. }
  2323.  
  2324.  
  2325.  
  2326.  
  2327.  
  2328.  
  2329.  
  2330.  
  2331. int mgetfiles (void)
  2332. {
  2333. if (filesflag) 
  2334.     {
  2335.     filesflag = 0;
  2336.     getreadmes = 1;
  2337.     SetMenuValues();     
  2338.     }
  2339.     else 
  2340.     filesflag = 1;
  2341. }
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349. int mgetreadmes (void)
  2350. {
  2351. if (getreadmes) 
  2352.     {getreadmes = 0; 
  2353.      filesflag = 1;
  2354.      SetMenuValues();
  2355.     }
  2356.     else 
  2357.     getreadmes = 1;
  2358. }
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365. int mgetsplit (void)
  2366. {
  2367. if (nosplit) nosplit = 0; else nosplit = 1;
  2368. SetMenuValues();    
  2369. }
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376. int mgetlinelength (void)
  2377. {
  2378. int lin;
  2379.  
  2380. requesttype = LINELENGTH_REQUESTTYPE;    /* This is a HORRIBLE way to program, but I don't want  */
  2381. lin = mgetfind();                                /* to try to change the parameters since it might screw */
  2382. requesttype = FIND_REQUESTTYPE;            /* up the mget_listview2 functions...                 */
  2383.  
  2384. if (lin >  0) maxoutputlinelength = lin;
  2385. }
  2386.  
  2387.  
  2388.  
  2389.  
  2390. int mgetoutputfile (void)
  2391. {
  2392. int lin;
  2393.  
  2394. requesttype = OUTPUTFILE_REQUESTTYPE;    /* This is a HORRIBLE way to program, but I don't want  */
  2395. lin = mgetfind();                                /* to try to change the parameters since it might screw */
  2396. requesttype = FIND_REQUESTTYPE;            /* up the mget_listview2 functions...                        */
  2397.  
  2398. }
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.  
  2405. void PrintList(struct List *thislist)
  2406. {
  2407. struct Node *nodecurrent = thislist->lh_Head;
  2408.  
  2409. fprintf(fpOut,"thislist = %p\n",thislist);
  2410.  
  2411.  while (nodecurrent != NULL)
  2412.  {
  2413.     if (nodecurrent->ln_Name == NULL) 
  2414.         fprintf(fpOut,"[ <NULL> ]\n"); 
  2415.     else 
  2416.         fprintf(fpOut,"[%s]\n",nodecurrent->ln_Name);
  2417.  
  2418.     nodecurrent = nodecurrent->ln_Succ;
  2419.  }
  2420.     
  2421. return();
  2422. }
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431. int mgetopenfile (void)
  2432. {
  2433. FILE *test = NULL;
  2434.  
  2435.  memset(inputfile,NUL,sizeof(inputfile));
  2436.  
  2437.  SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  2438.  
  2439.  while (test == NULL) 
  2440.     {
  2441.     if (RequestAFile(inputfile) == 0) 
  2442.         {
  2443.         ClearPointer(mgetWnd);
  2444.         return(0);
  2445.         }
  2446.     test = fopen(inputfile,"r");
  2447.     }
  2448.  
  2449.  fclose(test);
  2450.  SetReqDefaults(inputfile);
  2451.  
  2452.  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  2453.  FreeFileNodes(filelist); 
  2454.  FreeMem(filelist,sizeof(struct List));
  2455.  added_bytes -= sizeof(struct List);
  2456.  ClearPointer(mgetWnd);
  2457.  
  2458.  if (!(filelist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  2459.     {
  2460.     MakeReq("mgetOpen : Couldn't create filelist!  Out of memory?\n",NULL,"Uh-oh");
  2461.     return(0);
  2462.     }
  2463.  added_bytes += sizeof(struct List);
  2464.         
  2465.  /* These are all dependant on a given filelist, so RESET! */
  2466.  filelist_length = 0;
  2467.  search_current = NULL;
  2468.  search_index = 0;
  2469.  
  2470.  NewList(filelist);      
  2471.  ReadmyFile();
  2472.  if ((nKeepSorted[0] == 1)&&(!noparse)) SortList(filelist,nSortType[0]);  /* keep sorted if that is selected! */
  2473.  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  2474.  search_current = NULL;
  2475.  search_index = 0;
  2476.  ChangeWindowTitle();
  2477. return(1);
  2478. }
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485.  
  2486.  
  2487. int mgetappend(void)
  2488. {
  2489. int returnme = 0;
  2490.  
  2491. /* memset(inputfile,NUL,sizeof(inputfile)); */
  2492.  
  2493. GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  2494. returnme = ReadmyFile();
  2495. ChangeWindowTitle();
  2496. if ((nKeepSorted[0] == 1)&&(!noparse)) SortList(filelist,nSortType[0]);  /* keep sorted if that is selected! */
  2497. GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  2498. return(returnme);
  2499. }
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.  
  2506. int mgetCloseWindow (void)
  2507. {
  2508. done=TRUE;
  2509. }
  2510.  
  2511.  
  2512.  
  2513.  
  2514.  
  2515.  
  2516.  
  2517.  
  2518.  
  2519. void SetMenuValues (void)
  2520. {
  2521. struct Menu *currentMenu = mgetMenus;
  2522. struct MenuItem *currentItem, *currentSub;
  2523.  
  2524.  if (currentMenu == NULL)
  2525.     {
  2526.     MakeReq("SetMenuValues:  error, mgetMenus is NULL!",NULL,"Huh?");
  2527.     return;
  2528.     }
  2529.     
  2530.  if (mgetWnd != NULL) ClearMenuStrip(mgetWnd);
  2531.  
  2532.  /* Make sure the CaseSensitive item in the second menu is checked correctly. */    
  2533.  currentMenu = currentMenu->NextMenu;     /* Search Menu */
  2534.  currentItem = currentMenu->FirstItem;        /* #1 : Find Forward */
  2535.  currentItem = currentItem->NextItem;        /* #2 : Find Backward*/
  2536.  currentItem = currentItem->NextItem;        /* #3 : Find from Top */
  2537.  currentItem = currentItem->NextItem;        /* #4 : Find from Bottom */
  2538.  currentItem = currentItem->NextItem;        /* #5 : Find Next */
  2539.  currentItem = currentItem->NextItem;        /* #5 : Find Previous */
  2540.  currentItem = currentItem->NextItem;     /* #6 : Find Current */
  2541.  currentItem = currentItem->NextItem;     /* #6 : Select */
  2542.  currentItem = currentItem->NextItem;     /* #6 : Deselect */
  2543.  currentItem = currentItem->NextItem;        /* #6 : Case Sensitive. */
  2544.  
  2545.  if (searchcasesensitive)  currentItem->Flags |= CHECKED; 
  2546.             else  currentItem->Flags &= ~(CHECKED);    
  2547.  
  2548.  /* next we do the Sort menu. */
  2549.  currentMenu = currentMenu->NextMenu;
  2550.  if (noparse) currentMenu->Flags &= ~(MENUENABLED);
  2551.        else currentMenu->Flags |= MENUENABLED;
  2552.  
  2553.  currentItem = currentMenu->FirstItem;    /* #1: Files List */
  2554.  currentSub = currentItem->SubItem;    /* #1.1 : By Directory */
  2555.  
  2556.  currentSub = currentSub->NextItem;    /* #1.2 : By Size */
  2557.  
  2558.  currentSub = currentSub->NextItem;    /* #1.3 : By FileName */
  2559.  currentSub = currentSub->NextItem;    /* #1.4 : By Description */
  2560.  currentSub = currentSub->NextItem;       /* #1.5 : By Age */
  2561.  currentSub = currentSub->NextItem;       /* #1.6 : Keep Sorted */
  2562.  if (nKeepSorted[0] == 0) currentSub->Flags &= ~(CHECKED);
  2563.                            else currentSub->Flags |= CHECKED;
  2564.  
  2565.  currentItem = currentItem->NextItem;    /* #2: Get List */
  2566.  currentSub = currentItem->SubItem;    /* #2.1 : By Directory */
  2567.  currentSub = currentSub->NextItem;    /* #2.2 : By Size */
  2568.  currentSub = currentSub->NextItem;    /* #2.3 : By FileName */
  2569.  currentSub = currentSub->NextItem;    /* #2.4 : By Description */
  2570.  currentSub = currentSub->NextItem;       /* #2.5 : By Age */
  2571.  currentSub = currentSub->NextItem;        /* #2.6 : Keep Sorted */
  2572.  if (nKeepSorted[1] == 0) currentSub->Flags &= ~(CHECKED);
  2573.                            else currentSub->Flags |= CHECKED;
  2574.  
  2575.                                       
  2576.  currentItem = currentItem->NextItem;    /* #3: Sort Type */
  2577.  currentSub = currentItem->SubItem;    /* #3.1: Tree Sort */
  2578.  if (nSortAlgorithm == TREESORT) currentSub->Flags |= CHECKED;
  2579.                                      else currentSub->Flags &= ~(CHECKED);
  2580.  currentSub = currentSub->NextItem;        /* #3.2: Bubble Sort */
  2581.  if (nSortAlgorithm == BUBBLESORT)   currentSub->Flags |= CHECKED;
  2582.                                           else currentSub->Flags &= ~(CHECKED);
  2583.  
  2584.  currentItem = currentItem->NextItem;    /* #4: Case Sensitive */
  2585.  if (sortcasesensitive == FALSE) currentItem->Flags &= ~(CHECKED);
  2586.                                       else currentItem->Flags |= (CHECKED);
  2587.                                         
  2588.                           
  2589.  /* Output menu. */
  2590.  currentMenu = currentMenu->NextMenu;
  2591.  
  2592.  currentItem = currentMenu->FirstItem;        /* #1: Aminet Parse */
  2593.  
  2594.  if (noparse) currentItem->Flags &= ~(CHECKED);
  2595.        else currentItem->Flags |= CHECKED;
  2596.        
  2597.        
  2598.  currentItem = currentItem->NextItem;        /* #2: Get Files */
  2599.  
  2600.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  2601.        else currentItem->Flags |= ITEMENABLED;
  2602.  if (filesflag) currentItem->Flags |= CHECKED;
  2603.           else currentItem->Flags &= ~(CHECKED);
  2604.           
  2605.  currentItem = currentItem->NextItem;        /* #3: Get Readmes */
  2606.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  2607.        else currentItem->Flags |= ITEMENABLED;
  2608.  if (getreadmes) currentItem->Flags |= CHECKED;
  2609.            else currentItem->Flags &= ~(CHECKED);
  2610.     
  2611.  currentItem = currentItem->NextItem;        /* #4: Split Commands */
  2612.  
  2613.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  2614.        else currentItem->Flags |= ITEMENABLED;
  2615.  if (nosplit) currentItem->Flags &= ~(CHECKED);
  2616.            else currentItem->Flags |= CHECKED;
  2617.            
  2618.  
  2619.  currentItem = currentItem->NextItem;        /* #5: Use CD's */
  2620.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  2621.        else currentItem->Flags |= ITEMENABLED;
  2622.  if (simplepaths) currentItem->Flags |= CHECKED;
  2623.            else currentItem->Flags &= ~(CHECKED);
  2624.            
  2625.  currentItem = currentItem->NextItem;        /* #6: Line length */
  2626.  if ((noparse)||(nosplit)) currentItem->Flags &= ~(ITEMENABLED);
  2627.        else currentItem->Flags |= ITEMENABLED;
  2628.  
  2629.  ResetMenuStrip( mgetWnd, mgetMenus );                 
  2630. }
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637. /* Turns all \n's in input string into <space><newline>'s */
  2638. void FindReturns(char *mystring)
  2639. {
  2640. char *thischar=mystring, *prevchar=mystring;
  2641.  
  2642.  while (*thischar != NULL)
  2643.     {
  2644.     
  2645.     if ( (*prevchar  ==   92) &&                        /* any '/'s ? */
  2646.          ((*thischar ==   78)||(*thischar == 110)) &&      /* N's or n's */
  2647.          (prevchar   !=  NULL) &&                        /* Sanity chk */
  2648.          (thischar   !=  NULL))
  2649.         
  2650.         {
  2651.         *prevchar = ' ';   /* set this to a space--easier than shortening string */
  2652.         *thischar = 10;   /* and end this line with a newline char */
  2653.         }
  2654.     
  2655.     prevchar = thischar;
  2656.     thischar++;
  2657.     }
  2658. }
  2659.  
  2660.  
  2661.  
  2662.  
  2663.  
  2664.  
  2665.  
  2666.  
  2667.  
  2668. int AddFile(struct List *mylist, char *newstring)
  2669. {
  2670. struct Node *newnode;
  2671. char *newname, *i;
  2672. const char newlinechar = 10, spacechar = ' ';
  2673. UBYTE diff = MAXFILELINELENGTH;
  2674. const int minlinelength = 1;
  2675. int nStringLength;
  2676.  
  2677.  if (keepblanklines == 1) minlinelength = 0;
  2678.  if (newstring == NULL) return(0);
  2679.   
  2680.  /* remove nasty end-of-line carriage returns */
  2681.  nStringLength = strlen(newstring);
  2682.  if (newstring[nStringLength - 2] == '\r') 
  2683.  {
  2684.           newstring[nStringLength - 2] = ' ';
  2685.           nStringLength -= 2;
  2686.  }
  2687.  if (nStringLength < minlinelength) return(0); 
  2688.  
  2689.  if (!( newnode = AllocMem(sizeof(struct Node),MEMF_CLEAR) ))
  2690.     {
  2691.         /* emergency bailout! */
  2692.        FreeFileNodes(filelist); 
  2693.        filelist = NULL;
  2694.         FreeMem(filelist,sizeof(struct List));
  2695.         added_bytes -= sizeof(struct List);
  2696.         MakeReq("AddFile:  Aborting due to lack of memory",NULL,"Add 4 megs and retry");
  2697.         CleanUp();
  2698.         exit(20);
  2699.     }
  2700.  added_bytes += sizeof(struct Node);
  2701.     
  2702.  i = strchr(newstring, (char) newlinechar);
  2703.  if (i != NULL) diff = i-newstring;  /* number of chars into the string where newline is! */
  2704.  
  2705.  if (!( newname = AllocMem(diff+1,MEMF_CLEAR) ))
  2706.     {
  2707.         /* emergency bailout! */
  2708.         FreeMem(newnode,sizeof(struct Node));    /* get rid of that last Node */
  2709.        FreeFileNodes(filelist); 
  2710.        filelist = NULL;
  2711.         FreeMem(filelist,sizeof(struct List));
  2712.         added_bytes -= sizeof(struct List);
  2713.         MakeReq("AddFile:  Aborting due to lack of memory",NULL,"Add 4 megs and retry");
  2714.         CleanUp();
  2715.         exit(20);
  2716.     }
  2717.   added_bytes += diff+1;
  2718.     
  2719. strncpy(newname,newstring,diff);   /* copy over the bytes */
  2720.  
  2721. newnode->ln_Pri = diff - 126;        /* store string length in unused field */
  2722. newnode->ln_Name=newname;          /* and set ze pointer! */
  2723.  
  2724. AddTail(mylist, newnode);
  2725. return(1);
  2726. }
  2727.  
  2728.  
  2729.  
  2730. /* Prints out a file.  Makes sure there is a sEndOfLineString after the end of every line */
  2731. int PrintFile(char *szFileName, int PrintReturnFirst)
  2732. {
  2733.     FILE *input_file = fopen(szFileName,"r");
  2734.     char inputline[MAXFILELINELENGTH], *a, *b;
  2735.     int nLen;
  2736.  
  2737.      if (input_file == NULL) 
  2738.      {
  2739.         return(0);
  2740.      }
  2741.  
  2742.      if (PrintReturnFirst == 1)
  2743.      {
  2744.          fprintf(fpOut,sEndOfLineString);
  2745.          
  2746.      }
  2747.          
  2748.     /* Read until we get a line-end */
  2749.     while(!feof(input_file))
  2750.     {
  2751.         memset(inputline,NUL,MAXFILELINELENGTH);
  2752.         fgets(inputline,MAXFILELINELENGTH,input_file);  /* Read up to MAXFILELINELENGTH chars from inputfile */
  2753.         
  2754.         nLen = strlen(inputline);
  2755.         
  2756.         if (nLen >= 2)
  2757.         {
  2758.             /* make sure that it ends in a sEndOfLineString */
  2759.             a = &inputline[strlen(inputline)-2];
  2760.             b = &inputline[strlen(inputline)-1];
  2761.             
  2762.             if ((*a == '\r')&&(*b == '\n')) /* the easy case */
  2763.             {
  2764.                 fprintf(fpOut,"%s",inputline);
  2765.             }
  2766.             else
  2767.             {
  2768.                 if ((*a != '\r')&&(*b == '\n'))  /* the normal case, for Amigas */
  2769.                 {
  2770.                 /* make the newline a return, and then append a newline */
  2771.                     *b = '\r';
  2772.                     fprintf(fpOut,"%s\n",inputline);
  2773.                 }
  2774.                 else
  2775.                 {
  2776.                 if ((*a == '\r')&&(*b != '\n'))    /* the abnormal case */
  2777.                     {
  2778.                         *b = '\n';
  2779.                         fprintf(fpOut,"%s",inputline);
  2780.                     }
  2781.                     else
  2782.                     {
  2783.                         /* *a != \r, *b != \n */
  2784.                         fprintf(fpOut,"%s%s",inputline,sEndOfLineString);
  2785.                     }
  2786.                 }
  2787.             }
  2788.         }
  2789.         else
  2790.         if (nLen == 1) fprintf(fpOut,sEndOfLineString);
  2791.     }    
  2792.     fclose(input_file);
  2793.     return(1);
  2794. }
  2795.  
  2796.  
  2797.  
  2798. /* returns the number of lines successfully parsed and added to the list */
  2799. int ReadmyFile(void)
  2800. {
  2801. FILE *input_file = NULL;
  2802. char inputline[MAXFILELINELENGTH];
  2803. char *firstnull;
  2804. int nullpos = 0, okline = 0, nUpdate = 50;
  2805. int filelength = 0, failed_lines = 0;
  2806. int minlinelength = 1;
  2807.  
  2808. if (keepblanklines == 1) minlinelength = 0;
  2809.  
  2810. SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  2811.  
  2812.  while (input_file == NULL) 
  2813.     {
  2814.     input_file = fopen(inputfile,"r");
  2815.     if ((input_file == NULL)&&(RequestAFile(inputfile) == 0)) 
  2816.         {
  2817.         ClearPointer(mgetWnd);
  2818.         return(0);
  2819.         }
  2820.     }
  2821.     
  2822.  SetReqDefaults(inputfile);
  2823.  
  2824.  while (!feof(input_file))
  2825.     {
  2826.     filelength++;        
  2827.     okline=0;  
  2828.     /* Read until we get a line-end */
  2829.     while((okline==0)&&(!feof(input_file)))
  2830.         {
  2831.         memset(inputline,NUL,MAXFILELINELENGTH);
  2832.         fgets(inputline,MAXFILELINELENGTH,input_file);  /* Read up to MAXFILELINELENGTH chars from inputfile */
  2833.         firstnull = strchr(inputline,(char) 10); /* Find address of carriage return */
  2834.         nullpos = firstnull - inputline;           /* Subtract to get return pos */
  2835.         if ((nullpos >= minlinelength)&&(nullpos < MAXFILELINELENGTH)) okline=1;
  2836.         }
  2837.     
  2838.     if ((nullpos < MAXFILELINELENGTH)||(noparse))
  2839.           {
  2840.               if (AddFile(filelist, inputline) == TRUE)
  2841.               {
  2842.                   filelist_length++;
  2843.  
  2844.                     if (nUpdate == 0)
  2845.                     {
  2846.                         sprintf(windowtitle,"Loading: %i",filelist_length);   
  2847.                         SetWindowTitles(mgetWnd, windowtitle , (char *) ~0);                   
  2848.                         nUpdate = 50;
  2849.                     }
  2850.                     else
  2851.                     {
  2852.                         nUpdate--;
  2853.                     }
  2854.                  }
  2855.               else
  2856.               {
  2857.                   failed_lines++;
  2858.               }
  2859.           }
  2860.           else
  2861.           {
  2862.               failed_lines++;
  2863.           }
  2864.               
  2865.     }
  2866.  
  2867. fclose(input_file);
  2868. ClearPointer(mgetWnd);    
  2869. return(filelist_length);
  2870. }
  2871.  
  2872.  
  2873.  
  2874.  
  2875.  
  2876.  
  2877.  
  2878.  
  2879.  
  2880.  
  2881.  
  2882.  
  2883. VOID FreeFileNodes(struct List *mylist)
  2884. {
  2885. struct Node *nextnode,*worknode = mylist->lh_Head;  
  2886. const int nodesize = sizeof(struct Node);
  2887.  
  2888.  while (nextnode = (worknode->ln_Succ))
  2889.     {
  2890.     if (worknode->ln_Name != NULL)
  2891.         {
  2892.         FreeMem(worknode->ln_Name,worknode->ln_Pri+127);
  2893.         added_bytes -= worknode->ln_Pri+127;
  2894.         }        
  2895.     FreeMem(worknode,nodesize);
  2896.     worknode = nextnode;
  2897.     added_bytes -= nodesize;
  2898.     }
  2899. }
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  
  2909.  
  2910.  
  2911. void ChangeWindowTitle(void)
  2912. {
  2913.     char *fstring = inputfile, *f2;
  2914.     char sSubString[60];
  2915.     int charlength = (windowwidth-81)/8 - 40;
  2916.  
  2917.     if (charlength <= 0) 
  2918.     {
  2919.         fstring = sSubString;
  2920.         fstring[0] = NUL;
  2921.     }
  2922.     else
  2923.     if (strlen(fstring) > charlength)
  2924.     {
  2925.         f2 = inputfile + strlen(inputfile) - charlength - 1;    
  2926.         if (f2 > inputfile)
  2927.         {
  2928.             fstring = sSubString;
  2929.             strcpy(fstring,f2);
  2930.         }
  2931.     }    
  2932.     sprintf(windowtitle,"(%s) %i files, %u kilobytes selected.",fstring, files_selected, kbytes_selected);   
  2933.     SetWindowTitles(mgetWnd, windowtitle , (char *) ~0); 
  2934.     return();
  2935. }
  2936.  
  2937.  
  2938.  
  2939.  
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945. VOID UpdateByteCount(char *mystring, int addorsub)
  2946. {
  2947. kbytes_selected = kbytes_selected + (AminetFileSize(mystring) * addorsub);
  2948. return();
  2949. }
  2950.  
  2951.  
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.  
  2959.  
  2960.  
  2961. VOID CleanUp(void)
  2962. {
  2963.  
  2964. if ((fpOut != stdout)&&(fpOut != NULL)) fclose(fpOut);
  2965.  
  2966. if (listfontdata)  CloseFont(listfontdata);
  2967. if (windowisopen)  {ClosemgetWindow();  windowisopen = FALSE; mgetWnd = NULL;}
  2968. if (screenisopen)  {CloseDownScreen();  screenisopen = FALSE; Scr = NULL;}
  2969. if (filelist)        
  2970.                 {
  2971.                 FreeFileNodes(filelist); 
  2972.                 FreeMem(filelist,sizeof(struct List));
  2973.                 added_bytes -= sizeof(struct List);
  2974.                }
  2975. if (getlist) 
  2976.               {
  2977.                 FreeFileNodes(getlist);
  2978.                 FreeMem(getlist,sizeof(struct List));
  2979.                 added_bytes -= sizeof(struct List);
  2980.                }
  2981. if (WorkbenchBase) CloseLibrary((struct Library *)WorkbenchBase);
  2982. if (IconBase)         CloseLibrary((struct Library *)IconBase);
  2983. if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  2984. if (AslBase)        CloseLibrary((struct Library *)AslBase);
  2985. if (UtilityBase)   CloseLibrary((struct Library *)UtilityBase);
  2986. if (GraphicsBase)  CloseLibrary((struct GraphicsLib *)GraphicsBase);
  2987. if (GadToolsBase)  CloseLibrary((struct Library *)GadToolsBase);
  2988. return();
  2989. }
  2990.  
  2991.  
  2992.  
  2993.  
  2994.  
  2995.  
  2996.  
  2997.  
  2998.  
  2999.  
  3000.  
  3001. int RequestAFile(char *szBuffer)
  3002. {
  3003. int rvalue = 1;
  3004.  
  3005. if (strlen(defDir) == 0) strcpy(defDir,"ram:");
  3006. if (strlen(defFile)== 0) strcpy(defFile,"RECENT");
  3007.  
  3008. struct TagItem frtags[] =
  3009. {
  3010.     ASL_Hail,        (ULONG)"Select a text file to browse.",
  3011.     ASL_Height,    350,
  3012.     ASL_Width,    320,
  3013.     ASL_LeftEdge,    50,
  3014.     ASL_TopEdge,    35,
  3015.     ASL_OKText,    (ULONG)"Okay",
  3016.     ASL_CancelText,(ULONG)"Cancel",
  3017.     ASL_File,        defFile,
  3018.     ASL_Dir,         defDir,
  3019.     ASL_Window,    mgetWnd,
  3020.     TAG_DONE
  3021. };
  3022.  
  3023. struct FileRequester *fr;
  3024.  
  3025. fr = (struct FileRequester *) AllocAslRequest(ASL_FileRequest, frtags);
  3026.  
  3027. if (fr == NULL) 
  3028.     {
  3029.     rvalue = 0 ;
  3030.     }
  3031.  
  3032.  if ((rvalue)&&(AslRequest(fr, NULL)))
  3033.     {
  3034.     strcpy(szBuffer,fr->rf_Dir);
  3035.     strncpy(defDir,fr->rf_Dir,sizeof(defDir));
  3036.     strncpy(defFile,fr->rf_File,sizeof(defFile));
  3037.     if ((defDir[strlen(defDir)-1] != '/')&&
  3038.         (defDir[strlen(defDir)-1] != ':')) strcat(szBuffer,"/");
  3039.     strcat(szBuffer,fr->rf_File);
  3040.     }
  3041.     else
  3042.     rvalue = 0;
  3043.     
  3044. if (fr != NULL) FreeAslRequest(fr);
  3045.  
  3046. return(rvalue);
  3047. }
  3048.  
  3049.  
  3050.  
  3051.  
  3052.  
  3053.  
  3054.  
  3055.  
  3056.  
  3057. void TurnOnAllMenuItems(struct Menu *myMenu)
  3058. {
  3059. struct MenuItem *mItem;
  3060.  
  3061.  while (myMenu != NULL)
  3062.     {
  3063.     mItem = myMenu->FirstItem;
  3064.     while (mItem != NULL)
  3065.         {
  3066.         mItem->Flags |= ITEMENABLED;
  3067.         mItem = mItem->NextItem;
  3068.         }
  3069.     myMenu = myMenu->NextMenu;
  3070.     }
  3071. return;
  3072. }
  3073.  
  3074.  
  3075.  
  3076.  
  3077.  
  3078.  
  3079.  
  3080.  
  3081.  
  3082.  
  3083. VOID SetReqDefaults(char *szFilePath)
  3084. {
  3085. char *sFileStart;
  3086.  
  3087.  sFileStart = strrchr(szFilePath,'/');
  3088.  if (sFileStart == NULL)
  3089.      {
  3090.      sFileStart = strrchr(szFilePath,':');
  3091.      if (sFileStart == NULL)
  3092.          {
  3093.          sFileStart = szFilePath;
  3094.          }
  3095.      }
  3096.  
  3097.  if (sFileStart != NULL) strncpy(defFile,sFileStart+(sFileStart != szFilePath),sizeof(defFile));
  3098.  if ((sFileStart != NULL)&&(sFileStart != szFilePath)) strncpy(defDir,szFilePath,(sFileStart - szFilePath) + 1);
  3099.  return();
  3100. }
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107. VOID UpperCase(char *sOldString)
  3108. {
  3109. char *i = sOldString;
  3110. const int diff = 'a' - 'A';
  3111.  
  3112.  if (sOldString == NULL) return();
  3113.  while (*i != '\0')
  3114.  {
  3115.     if ((*i >= 'a')&&(*i <= 'z')) *i = *i - diff;
  3116.     i++;
  3117.  }
  3118. return();
  3119. }
  3120.  
  3121.  
  3122.  
  3123.  
  3124.  
  3125. VOID LowerCase(char *sOldString)
  3126. {
  3127. char *i = sOldString;
  3128. const int diff = 'a' - 'A';
  3129.  
  3130.  if (sOldString == NULL) return();
  3131.  while (*i != '\0')
  3132.     {
  3133.     if ((*i >= 'A')&&(*i <= 'Z')) *i = *i + diff;
  3134.     i++;
  3135.     }
  3136.  
  3137. return();
  3138. }
  3139.  
  3140.  
  3141.  
  3142.  
  3143.  
  3144.  
  3145. int mgetoutput(void)
  3146. {
  3147. FILE *fpTemp = NULL;
  3148.  
  3149.         if (files_selected > 0) 
  3150.         {
  3151.             /* If no output name given, do default output... */
  3152.              if (strlen(sOutFileName) == 0)
  3153.              {
  3154.                  /* for Workbench, absolute default is ram:GadMget.output */
  3155.                  if (BStartedFromWB == TRUE)
  3156.                  {
  3157.                      fpTemp = fopen("ram:Gadmget.Output","w");
  3158.                      if (fpTemp == NULL) 
  3159.                      {
  3160.                         MakeReq("Error:  Couldn't open ram:GadMget.output for writing!",NULL,"Ok");
  3161.                         CleanUp();
  3162.                         exit(10);
  3163.                      }
  3164.                  }
  3165.                  else
  3166.                  {    /* for the CLI, default is stdout */
  3167.                      fpTemp = stdout;
  3168.                  }
  3169.              }
  3170.              else
  3171.              {
  3172.                  /* open requested output file for writing */
  3173.                  fpTemp = fopen(sOutFileName,"w");
  3174.                  if (fpTemp == NULL)
  3175.                  {
  3176.                      MakeReq("Error:  Couldn't open output file!",NULL,"Ok");
  3177.                  }
  3178.              }
  3179.              
  3180.              fpOut = fpTemp;
  3181.             PrintFile(szHeaderFile,0);
  3182.             if (noparse) RawOutputList(getlist);
  3183.                        else OutputList(getlist); 
  3184.             PrintFile(szFooterFile,1);
  3185.             if (fpOut != stdout) fclose(fpOut);            
  3186.         }
  3187. return(0);
  3188. }
  3189.  
  3190.  
  3191.  
  3192. VOID ParseCliArgs(int argc, char *argv[])
  3193. {
  3194.  int nextpasslookfor = 0;
  3195.  FILE *fpTemp = NULL;
  3196.  
  3197.  memset(defDir,NUL,sizeof(defDir));
  3198.  memset(defFile,NUL,sizeof(defFile));
  3199.  memset(szHeaderFile,NUL,sizeof(szHeaderFile));
  3200.  memset(szFooterFile,NUL,sizeof(szFooterFile));
  3201.  memset(inputfile,NUL,sizeof(inputfile));
  3202.  
  3203.  if (argc > 1) 
  3204.      {
  3205.      strncpy(inputfile,argv[1],sizeof(inputfile));
  3206.      SetReqDefaults(inputfile);
  3207.      }
  3208.          
  3209.  if (*inputfile == '?')
  3210.     {
  3211.     fprintf(fpOut,"%s",template);
  3212.     CleanUp();
  3213.     exit(0);
  3214.     }
  3215.  
  3216.  
  3217.  for (int i=2; i<=argc; i++)
  3218.     {
  3219.     if (nextpasslookfor == 2)
  3220.         {
  3221.         strncpy(szPubScreenName,argv[i-1],sizeof(szPubScreenName));
  3222.         pubscreenname = szPubScreenName;
  3223.         screentype = USE_PUBSCREEN;
  3224.         continue;            /* skip to next loop */
  3225.         }
  3226.    if (nextpasslookfor == 7)         /* FILE PARAMETER */
  3227.          {
  3228.          strncpy(inputfile,argv[i-1],sizeof(inputfile));
  3229.          SetReqDefaults(inputfile);
  3230.          }
  3231.     if (nextpasslookfor == 9)        /* COMMAND PARAMETER */
  3232.         {
  3233.         strncpy(szCommandString,argv[i-1],sizeof(szCommandString));
  3234.         }
  3235.     if (nextpasslookfor == 16)    /* AMINETPATH PARAMETER */
  3236.         {
  3237.         strncpy(sAminetPathString,argv[i-1],sizeof(sAminetPathString));
  3238.         }
  3239.     if (nextpasslookfor == 17)    /* EOL PARAMETER */
  3240.         {
  3241.         strncpy(sEndOfLineString,argv[i-1],sizeof(sEndOfLineString));
  3242.         EOLParse(sEndOfLineString);
  3243.         }
  3244.  
  3245.     
  3246.     UpperCase(argv[i-1]);
  3247.  
  3248.     switch(nextpasslookfor)
  3249.     {    
  3250.     case(1):
  3251.         if (atoi(argv[i-1]) > 0)  maxoutputlinelength = atoi(argv[i-1]);
  3252.         break;
  3253.         
  3254.     /* case 2 is up above, before the Upper() command */
  3255.     
  3256.     case(3):        /* WIDTH PARAMETER */
  3257.         if (atoi(argv[i-1]) > 0)  windowwidth = 155;    /* min level */
  3258.         if (atoi(argv[i-1]) > 155) windowwidth = atoi(argv[i-1]);
  3259.         break;
  3260.     case(4):        /* HEIGHT PARAMETER */
  3261.         if (atoi(argv[i-1]) > 0) windowheight = 167;    /* min level */
  3262.         if (atoi(argv[i-1]) > 167) windowheight = atoi(argv[i-1]);
  3263.         break;
  3264.     case(5):        /* TOP PARAMETER */
  3265.         if (atoi(argv[i-1]) > 0) windowtop = atoi(argv[i-1]);
  3266.         break;
  3267.     case(6):        /* LEFT PARAMETER */
  3268.         if (atoi(argv[i-1]) > 0) windowleft = atoi(argv[i-1]);
  3269.         break;
  3270.         
  3271.     /* Case 7 is up above, before the Upper() command */
  3272.     
  3273.     case(8):        /* OUTPUT PARAMETER */
  3274.         strncpy(sOutFileName,argv[i-1],sizeof(sOutFileName));
  3275.         break;
  3276.     
  3277.     /* Case 9 is up above, before the Upper() command */
  3278.     
  3279.     case(10):        /* HEADER PARAMETER */
  3280.         strncpy(szHeaderFile,argv[i-1],sizeof(szHeaderFile));
  3281.         break;
  3282.         
  3283.     case(11):        /* FOOTER PARAMETER */
  3284.         strncpy(szFooterFile,argv[i-1],sizeof(szFooterFile));
  3285.         break;
  3286.  
  3287.     case(12):        /* FONT PARAMETER */
  3288.         strncpy(sListFontName,argv[i-1],sizeof(sListFontName));
  3289.         LowerCase(sListFontName);
  3290.         if (strstr(sListFontName,".font") == NULL) strncat(sListFontName,".font",sizeof(sListFontName));
  3291.         break;
  3292.         
  3293.     case(13):        /* FONTSIZE PARAMETER */
  3294.         if (atoi(argv[i-1]) > 0) nListFontSize = atoi(argv[i-1]);
  3295.         break;
  3296.     
  3297.     case(14):        /* FILESORT PARAMETER */
  3298.         LowerCase(argv[i-1]);
  3299.         if (strcmp(argv[i-1],"directory") == 0)   nSortType[0] = SORTBYDIR;
  3300.         if (strcmp(argv[i-1],"filename") == 0)    nSortType[0] = SORTBYNAME;
  3301.         if (strcmp(argv[i-1],"size") == 0)        nSortType[0] = SORTBYSIZE;
  3302.         if (strcmp(argv[i-1],"description") == 0) nSortType[0] = SORTBYDESC;
  3303.         break;
  3304.             
  3305.     case(15):        /* GETSORT PARAMETER */
  3306.         LowerCase(argv[i-1]);
  3307.         if (strcmp(argv[i-1],"directory") == 0)   nSortType[1] = SORTBYDIR;
  3308.         if (strcmp(argv[i-1],"filename") == 0)    nSortType[1] = SORTBYNAME;
  3309.         if (strcmp(argv[i-1],"size") == 0)        nSortType[1] = SORTBYSIZE;
  3310.         if (strcmp(argv[i-1],"description") == 0) nSortType[1] = SORTBYDESC;
  3311.         break;
  3312.  
  3313.     /* Case 16 is up above the Upper() command */
  3314.  
  3315.     /* Case 17 is up above the Upper() command */
  3316.             
  3317.     default:
  3318.         /* nothing */
  3319.         break;        
  3320.     }
  3321.     nextpasslookfor = 0;
  3322.     
  3323.     
  3324.     
  3325.     if (strcmp(argv[i-1],"NOAPPWINDOW") == 0) appwindow         = FALSE;
  3326.     if (strcmp(argv[i-1],"SEARCHCASESENSITIVE") == 0) searchcasesensitive = TRUE;    
  3327.     if (strcmp(argv[i-1],"SORTCASESENSITIVE") == 0) sortcasesensitive= TRUE;    
  3328.     if (strcmp(argv[i-1],"CASESENSITIVE") == 0) 
  3329.             {
  3330.                 sortcasesensitive= TRUE;    
  3331.                 searchcasesensitive = TRUE;
  3332.             }
  3333.  
  3334.     if (strcmp(argv[i-1],"NOPARSE") == 0)         noparse             = TRUE;
  3335.     if (strcmp(argv[i-1],"NOCOMMAND") == 0)     nocommand        = TRUE;
  3336.     if (strcmp(argv[i-1],"NOSPLIT") == 0)         nosplit             = TRUE;
  3337.     if (strcmp(argv[i-1],"GETREADMES") == 0)     getreadmes         = TRUE;    
  3338.     if (strcmp(argv[i-1],"NOCD") == 0)            nocd                = TRUE;
  3339.    if (strcmp(argv[i-1],"NOFILES") == 0)     
  3340.                                             {
  3341.                                             filesflag     = FALSE;
  3342.                                             getreadmes  = TRUE;
  3343.                                             }
  3344.      if (strcmp(argv[i-1],"LINELENGTH") == 0)           nextpasslookfor= 1;
  3345.      if (strcmp(argv[i-1],"PUBSCREEN") == 0)           nextpasslookfor= 2;
  3346.     if (strcmp(argv[i-1],"DEFPUBSCREEN") == 0)       screentype = USE_PUBSCREEN;     
  3347.     if ((strcmp(argv[i-1],"WBSCREEN") == 0)||
  3348.         (strcmp(argv[i-1],"WORKBENCHSCREEN") == 0)) screentype = USE_WBSCREEN;
  3349.     if (strcmp(argv[i-1],"NOSIMPLEPATHS") == 0)       simplepaths  = FALSE;    
  3350.     if (strcmp(argv[i-1],"KEEPBLANKLINES") == 0)    keepblanklines = TRUE;
  3351.     if (strcmp(argv[i-1],"KEEPFILESSORT") == 0)   nKeepSorted[0] = TRUE;
  3352.     if (strcmp(argv[i-1],"KEEPGETSORT") == 0)     nKeepSorted[1] = TRUE;
  3353.                                                                                     
  3354.     if (strcmp(argv[i-1],"WIDTH") == 0)            nextpasslookfor = 3;
  3355.     if (strcmp(argv[i-1],"HEIGHT") == 0)        nextpasslookfor = 4;
  3356.     if (strcmp(argv[i-1],"TOP") == 0)            nextpasslookfor = 5;
  3357.     if (strcmp(argv[i-1],"LEFT") == 0)            nextpasslookfor = 6;
  3358.     if (strcmp(argv[i-1],"FILE") == 0)            nextpasslookfor = 7;
  3359.     if (strcmp(argv[i-1],"OUTPUT") == 0)        nextpasslookfor = 8;
  3360.     if (strcmp(argv[i-1],"COMMAND") == 0)        nextpasslookfor = 9;
  3361.     if (strcmp(argv[i-1],"HEADER") == 0)        nextpasslookfor = 10;
  3362.     if (strcmp(argv[i-1],"FOOTER") == 0)        nextpasslookfor = 11;
  3363.     if (strcmp(argv[i-1],"FONT") == 0)        nextpasslookfor = 12;
  3364.     if (strcmp(argv[i-1],"FONTSIZE") == 0)    nextpasslookfor = 13;
  3365.     if (strcmp(argv[i-1],"SIZE") == 0)        nextpasslookfor = 13;
  3366.     if (strcmp(argv[i-1],"FILESORT") == 0)    nextpasslookfor = 14;
  3367.     if (strcmp(argv[i-1],"GETSORT") == 0)     nextpasslookfor = 15;
  3368.     if (strcmp(argv[i-1],"AMINETPATH") == 0)  nextpasslookfor = 16;
  3369.     if (strcmp(argv[i-1],"EOL") == 0)         nextpasslookfor = 17;
  3370.     }
  3371.  
  3372. return();
  3373. }
  3374.  
  3375.  
  3376.  
  3377.  
  3378.  
  3379.  
  3380.  
  3381.  
  3382.  
  3383.  
  3384. VOID wbmain(struct WBStartup *argv)
  3385. {
  3386. BStartedFromWB = TRUE;
  3387. IconBase = OpenLibrary("icon.library",33);
  3388. if (IconBase == NULL)
  3389.      {
  3390.      exit(2);
  3391.      }
  3392. ParseWBArgs(argv);
  3393. main(0,argv);
  3394. }
  3395.  
  3396.  
  3397.  
  3398.  
  3399.  
  3400.  
  3401.  
  3402.  
  3403. VOID ParseWBArgs(struct WBStartup *argv)
  3404. {
  3405. struct WBArg *wb_arg = argv->sm_ArgList;
  3406. struct DiskObject *dobj;
  3407. char **toolarray, *sTemp;
  3408. FILE *fpTemp = NULL;
  3409.  
  3410.  
  3411. memset(defDir,NUL,sizeof(defDir));
  3412. memset(defFile,NUL,sizeof(defFile));
  3413. memset(szHeaderFile,NUL,sizeof(szHeaderFile));
  3414. memset(szFooterFile,NUL,sizeof(szFooterFile));
  3415.  
  3416.  
  3417. /* Parse the tooltypes from the program file */
  3418. dobj = GetDiskObject(wb_arg->wa_Name);
  3419.  
  3420. if (dobj != NULL)
  3421.  {
  3422.      toolarray = (char **) dobj->do_ToolTypes;
  3423.     if (toolarray != NULL)
  3424.     {
  3425.     
  3426.         if (sTemp = (char *) FindToolType(toolarray,"OUTPUT")) 
  3427.         {
  3428.           strncpy(sOutFileName,sTemp,sizeof(sOutFileName));
  3429.         }
  3430.                                             
  3431.         if (sTemp = (char *) FindToolType(toolarray,"FILE")) 
  3432.                 {
  3433.                 strncpy(inputfile,sTemp,sizeof(inputfile));
  3434.                 SetReqDefaults(inputfile);
  3435.                 }
  3436.         if (sTemp = (char *) FindToolType(toolarray,"NOPARSE"))       noparse     = TRUE;
  3437.         if (sTemp = (char *) FindToolType(toolarray,"NOCOMMAND"))      nocommand   = TRUE;
  3438.        if (sTemp = (char *) FindToolType(toolarray,"NOSPLIT"))       nosplit     = TRUE;    
  3439.        if (sTemp = (char *) FindToolType(toolarray,"GETREADMES"))  getreadmes  = TRUE;
  3440.         if (sTemp = (char *) FindToolType(toolarray,"NOFILES"))
  3441.                                                              {
  3442.                                                             filesflag     = FALSE;
  3443.                                                             getreadmes  = TRUE;
  3444.                                                             }
  3445.        if (sTemp = (char *) FindToolType(toolarray,"LINELENGTH"))
  3446.                    {
  3447.                    if (atoi(sTemp) > 0)  maxoutputlinelength = atoi(sTemp); 
  3448.                    }
  3449.                   
  3450.           if (sTemp = (char *) FindToolType(toolarray,"PUBSCREEN"))   
  3451.                       {
  3452.                       strcpy(szPubScreenName,sTemp);
  3453.                       pubscreenname = szPubScreenName;
  3454.                       screentype = USE_PUBSCREEN;
  3455.                       }
  3456.           
  3457.           if (sTemp = (char *) FindToolType(toolarray,"NOSIMPLEPATHS"))     simplepaths = FALSE;        
  3458.           if (sTemp = (char *) FindToolType(toolarray,"NOPARSE"))   noparse = TRUE;        
  3459.         if (sTemp = (char *) FindToolType(toolarray,"NOAPPWINDOW")) appwindow = FALSE;
  3460.         if (sTemp = (char *) FindToolType(toolarray,"WBSCREEN"))           screentype = USE_WBSCREEN;
  3461.         if (sTemp = (char *) FindToolType(toolarray,"WORKBENCHSCREEN")) screentype = USE_WBSCREEN;                                
  3462.         if (sTemp = (char *) FindToolType(toolarray,"NOCD"))                 nocd = TRUE;
  3463.         if (sTemp = (char *) FindToolType(toolarray,"KEEPBLANKLINES")) keepblanklines = TRUE;
  3464.         if (sTemp = (char *) FindToolType(toolarray,"KEEPFILESORT")) nKeepSorted[0] = TRUE;
  3465.         if (sTemp = (char *) FindToolType(toolarray,"KEEPGETSORT")) nKeepSorted[1] = TRUE;
  3466.         
  3467.         if (sTemp = (char *) FindToolType(toolarray,"WIDTH"))                             
  3468.                         {
  3469.                         if (atoi(sTemp) > 0)  windowwidth = 155;    /* min level */
  3470.                         if (atoi(sTemp) > 155) windowwidth = atoi(sTemp);
  3471.                         }
  3472.         if (sTemp = (char *) FindToolType(toolarray,"HEIGHT"))     
  3473.                         {                        
  3474.                         if (atoi(sTemp) > 0) windowheight = 167;    /* min level */
  3475.                         if (atoi(sTemp) > 167) windowheight = atoi(sTemp);
  3476.                         }
  3477.         if (sTemp = (char *) FindToolType(toolarray,"TOP"))                             
  3478.                         {
  3479.                         if (atoi(sTemp) > 0) windowtop = atoi(sTemp);
  3480.                         }
  3481.         if (sTemp = (char *) FindToolType(toolarray,"LEFT"))                             
  3482.                         {
  3483.                         if (atoi(sTemp) > 0) windowleft = atoi(sTemp);
  3484.                         }                    
  3485.         if (sTemp = (char *) FindToolType(toolarray,"SEARCHCASESENSITIVE"))                             
  3486.                         {
  3487.                         searchcasesensitive = 1;
  3488.                         }
  3489.         if (sTemp = (char *) FindToolType(toolarray,"SORTCASESENSITIVE"))                             
  3490.                         {
  3491.                         sortcasesensitive = 1;
  3492.                         }
  3493.         if (sTemp = (char *) FindToolType(toolarray,"CASESENSITIVE"))                             
  3494.                         {
  3495.                         searchcasesensitive = 1;
  3496.                         sortcasesensitive = 1;
  3497.                         }
  3498.  
  3499.         if (sTemp = (char *) FindToolType(toolarray,"COMMAND"))
  3500.                         {
  3501.                         strncpy(szCommandString,sTemp,sizeof(szCommandString));
  3502.                         }
  3503.         if (sTemp = (char *) FindToolType(toolarray,"HEADER"))
  3504.                         {
  3505.                         strncpy(szHeaderFile,sTemp,sizeof(szHeaderFile));
  3506.                         }
  3507.         if (sTemp = (char *) FindToolType(toolarray,"FOOTER"))
  3508.                         {
  3509.                         strncpy(szFooterFile,sTemp,sizeof(szFooterFile));
  3510.                         }
  3511.         if (sTemp = (char *) FindToolType(toolarray,"FONT"))
  3512.                         {
  3513.                         strncpy(sListFontName,sTemp,sizeof(sListFontName));
  3514.                         LowerCase(sListFontName);
  3515.                         if (strstr(sListFontName,".font") == NULL) strncat(sListFontName,".font",sizeof(sListFontName));
  3516.                         }
  3517.         if (sTemp = (char *) FindToolType(toolarray,"FONTSIZE"))
  3518.                         {
  3519.                         if (atoi(sTemp) > 0) nListFontSize = atoi(sTemp);
  3520.                         }
  3521.         if (sTemp = (char *) FindToolType(toolarray,"SIZE"))
  3522.                         {
  3523.                         if (atoi(sTemp) > 0) nListFontSize = atoi(sTemp);
  3524.                         }
  3525.         if (sTemp = (char *) FindToolType(toolarray,"FILESORT"))
  3526.                         {
  3527.                         LowerCase(sTemp);
  3528.                         if (strcmp(sTemp,"directory") == 0)   nSortType[0] = SORTBYDIR;
  3529.                         if (strcmp(sTemp,"filename") == 0)    nSortType[0] = SORTBYNAME;
  3530.                         if (strcmp(sTemp,"size") == 0)        nSortType[0] = SORTBYSIZE;
  3531.                         if (strcmp(sTemp,"description") == 0) nSortType[0] = SORTBYDESC;
  3532.                         }
  3533.         if (sTemp = (char *) FindToolType(toolarray,"GETSORT"))
  3534.                         {
  3535.                         LowerCase(sTemp);
  3536.                         if (strcmp(sTemp,"directory") == 0)   nSortType[1] = SORTBYDIR;
  3537.                         if (strcmp(sTemp,"filename") == 0)    nSortType[1] = SORTBYNAME;
  3538.                         if (strcmp(sTemp,"size") == 0)        nSortType[1] = SORTBYSIZE;
  3539.                         if (strcmp(sTemp,"description") == 0) nSortType[1] = SORTBYDESC;
  3540.                         }    
  3541.                         
  3542.         if (sTemp = (char *) FindToolType(toolarray,"AMINETPATH"))
  3543.                         strncpy(sAminetPathString,sTemp,sizeof(sAminetPathString));
  3544.         if (sTemp = (char *) FindToolType(toolarray,"EOL"))
  3545.                         {
  3546.                         strncpy(sEndOfLineString,sTemp,sizeof(sEndOfLineString));
  3547.                         EOLParse(sEndOfLineString);
  3548.                         }
  3549.                         
  3550.     }                     
  3551.  FreeDiskObject(dobj);
  3552.  }
  3553.  
  3554.  /* Get the name of the file extended_clicked, if there is one */
  3555.  if (argv->sm_NumArgs > 1) 
  3556.     {
  3557.     wb_arg++;    /* The first name is the programs name, the 2nd is the proj. icon */
  3558.     if (wb_arg->wa_Name != NULL) 
  3559.         {
  3560.         strncpy(inputfile,wb_arg->wa_Name,sizeof(inputfile));
  3561.         CurrentDir(wb_arg->wa_Lock);
  3562.         }
  3563.     }
  3564.     
  3565. return();
  3566. }
  3567.  
  3568.  
  3569.  
  3570.  
  3571.  
  3572.  
  3573.  
  3574.  
  3575.  
  3576.  
  3577. /********/
  3578. /* MAIN */
  3579. /********/
  3580. VOID main(int argc, char *argv[])
  3581. {
  3582. FILE *test = NULL;
  3583. ULONG winsig,signals;
  3584. BPTR olddir;
  3585.  
  3586. GraphicsBase = OpenLibrary("graphics.library",37);
  3587.  if (GraphicsBase==NULL)
  3588.     {
  3589.     fprintf(fpOut,"couldn't open Graphics.library v37!");
  3590.     CleanUp();
  3591.     return;
  3592.     }
  3593. UtilityBase = OpenLibrary("utility.library",37);
  3594.  if (UtilityBase==NULL)
  3595.     {
  3596.     fprintf(fpOut,"couldn't open utility.library v37!");
  3597.     CleanUp();
  3598.     return;
  3599.     }
  3600. GadToolsBase = OpenLibrary("gadtools.library",37);
  3601.  if (GadToolsBase==NULL)
  3602.     {
  3603.     fprintf(fpOut,"couldn't open gadtools.library v37!\n");
  3604.     CleanUp();
  3605.     return;
  3606.     }
  3607. AslBase = OpenLibrary("asl.library", 37L);
  3608.  if (AslBase == NULL)
  3609.     {
  3610.     fprintf(fpOut,"couldn't open asl.library v37!\n");
  3611.     CleanUp();
  3612.     return;
  3613.     }
  3614. IntuitionBase = OpenLibrary("intuition.library",37);
  3615.  if (IntuitionBase == NULL)
  3616.      {
  3617.      fprintf(fpOut,"Couldn't open intuition.library!\n");
  3618.      CleanUp();
  3619.      return;
  3620.      }
  3621. WorkbenchBase = OpenLibrary("workbench.library",37);
  3622.  if (WorkbenchBase == NULL)
  3623.      {
  3624.      fprintf(fpOut,"Couldn't open workbench.library!\n");
  3625.      CleanUp();
  3626.      return;
  3627.      }
  3628.  
  3629. /* construct program name from version string */
  3630. memset(pnamestring,NUL,20);
  3631. strcpy(pnamestring,version+6);
  3632.  
  3633. memset(searchstring,NUL,sizeof(searchstring));
  3634.  
  3635. if (argc>1) ParseCliArgs(argc,argv);
  3636.      
  3637. /* Now add data to listView */
  3638. /* First, initialize List filelist */
  3639.     
  3640.  if (!(filelist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  3641.     {
  3642.     MakeReq("Couldn't create filelist!  Out of memory?",NULL,"Oh, Dear");
  3643.     CleanUp();
  3644.     return();
  3645.     }
  3646.  added_bytes += sizeof(struct List);
  3647.     
  3648.  if (!(getlist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  3649.     {
  3650.     MakeReq("Couldn't create getlist!  Out of memory?",NULL,"Oh, Dear");
  3651.     CleanUp();
  3652.     return();
  3653.     }
  3654.  added_bytes += sizeof(struct List);
  3655.     
  3656.  NewList(filelist);
  3657.  NewList(getlist);
  3658.  
  3659.  
  3660.  lockscrnerror = SetupScreen();
  3661.  if (lockscrnerror)
  3662.     {
  3663.     if (BStartedFromWB == FALSE) printf("Couldn't open screen!\n",NULL,"Sigh");
  3664.     else
  3665.     MakeReq("Couldn't open screen!",NULL,NULL);
  3666.     
  3667.     CleanUp();
  3668.     return();
  3669.     }
  3670.  
  3671.  screenisopen = 1;
  3672.     
  3673.  winopenerror = OpenmgetWindow();
  3674.  if (winopenerror)
  3675.     {
  3676.     MakeReq("Couldn't open window!",NULL,"Sigh");
  3677.     CleanUp();
  3678.     return();
  3679.     }
  3680.  windowisopen = 1;
  3681.  
  3682.  if (ReadmyFile() > 0)
  3683.     {
  3684.         /* Sort if need be */
  3685.         if ((nKeepSorted[0] == 1)&&(!noparse)) SortList(filelist,nSortType[0]);
  3686.         
  3687.         /* First, make sure all the menus are enabled. */
  3688.         TurnOnAllMenuItems(mgetMenus);
  3689.         
  3690.         SetMenuValues();
  3691.     
  3692.         GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END); 
  3693.         files_selected = 0;
  3694.     
  3695.         if (noparse) SetWindowTitles(mgetWnd, "Please select desired lines now." , (char *) ~0); 
  3696.                    else ChangeWindowTitle();
  3697.         
  3698.         winsig = 1L << mgetWnd->UserPort->mp_SigBit;
  3699.         while (done==FALSE)
  3700.             {
  3701.             signals = Wait(winsig|appwinsig);
  3702.             if (signals&winsig) handlereturn = HandlemgetIDCMP();
  3703.             if (signals&appwinsig) 
  3704.                 {
  3705.                 while (amsg = (struct AppMessage *) GetMsg(awport))
  3706.                     {
  3707.                     argptr = amsg->am_ArgList;
  3708.                     if (argptr->wa_Name != NULL)
  3709.                         {
  3710.                         strcpy(inputfile,argptr->wa_Name);
  3711.                         if (argptr->wa_Lock != NULL) 
  3712.                             {
  3713.                             olddir = CurrentDir(argptr->wa_Lock);
  3714.                             SetReqDefaults(inputfile);
  3715.                              test = fopen(inputfile,"r");
  3716.                              if (test != NULL)
  3717.                                  {
  3718.                                  fclose(test);
  3719.                                  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  3720.                                 FreeFileNodes(filelist); 
  3721.                                  FreeMem(filelist,sizeof(struct List));
  3722.                                  added_bytes -= sizeof(struct List);
  3723.                                  ClearPointer(mgetWnd);
  3724.          
  3725.                                  if (!(filelist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  3726.                                     {
  3727.                                     MakeReq("AppOpen : Couldn't create filelist!  Out of memory?",NULL,"Ok");
  3728.                                     return;
  3729.                                     }
  3730.                                  added_bytes += sizeof(struct List);
  3731.                     
  3732.                                  filelist_length = 0;
  3733.                                  search_current = NULL;
  3734.                                  search_index = 0;
  3735.                                  
  3736.                                 NewList(filelist);
  3737.                                  ReadmyFile();
  3738.                                  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  3739.                                 CurrentDir(olddir);
  3740.                                 }
  3741.                                 else
  3742.                                 DisplayBeep(Scr);
  3743.                             }
  3744.                         }
  3745.                     ReplyMsg((struct Message *) amsg);
  3746.                     }
  3747.                 }
  3748.             }
  3749.         if (windowisopen)  ClosemgetWindow();
  3750.         if (screenisopen)  CloseDownScreen();
  3751.     
  3752.         mgetoutput();
  3753.     }
  3754. CleanUp();
  3755.         
  3756. exit(0);    
  3757. }
  3758.  
  3759. #endif
  3760.  
  3761.  
  3762.     
  3763.